Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

wpf - Resource dictionary resolved in one project but not another in same solution

I created a resource dictionary (Style.xaml) and put it in it's own assembly (ResourceSharing.dll). I then have a solution with two projects. In both projects, I added a reference to ResourceSharing.dll, and in App.xaml I added this code:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/ResourceSharing;component/Style.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

When I try to use a resource contained in the resource dictionary, something like

<Grid Background="{StaticResource GridBackgroundColor}">

In one project, that works. The changes are applied at design time, and everything builds, compiles, and runs. But in the other project, that line is underlined with a blue line and I get the error "The resource "GridBackgroundColor" could not be resolved.", but intellisense will autocomplete the resource name and the designer even shows the correct color square next to it. The code will build and run fine even with this error, it is only at design time that it has a problem.

Why would this happen in one project but not another? Could there be specific project settings that would cause this? And if so, what are some settings that would affect this?

I am running Visual Studio Professional 2019 v16.8.4

Note: The project that is not working was an existing project that I attempted to add this resource dictionary assembly reference to and utilize. The other project was added just to test the resource assembly.

Update: I've tried everything mentioned in this person's question and the answers: Design-time Error finding the Resource Dictionary - Inconsistent between projects

Update#2: This error does not occur when opening the solution in Visual Studio 2017

question from:https://stackoverflow.com/questions/65923434/resource-dictionary-resolved-in-one-project-but-not-another-in-same-solution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...