WPF Dynamic Resource: Warning Message - "The resource 'resource' could not be resolved."

myermian picture myermian · Mar 31, 2011 · Viewed 7.4k times · Source

Basically, I have a UserControl that uses a DynamicResources. The application compiles and runs fine using that resource, but it's a bit annoying to see this warning message. It makes me wonder if I'm doing it right and it's just a false positive, or if I'm doing it wrong and happen to slip through the cracks in it working.

<Grid Background="{DynamicResource AppDefaultBackgroundColor}">
...
</Grid>

So, if I used it correctly, how can I get rid of this warning message?
If I did not use it appropriately, what should it look like so I don't get a warning?

P.S. My application works and runs fine, but I prefer to not have any compilation warnings when compiling.

Answer

nazim hatipoglu picture nazim hatipoglu · Nov 30, 2011

You can map your resource like this

<Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="..\Resources\Theme.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Resources>

Theme.xaml must contain 'AppDefaultBackgroundColor' like this

 <Color x:Key="AppDefaultBackgroundColor">#FF77C6FB</Color>