Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 659
myermian Avatar asked Mar 31 '11 20:03

myermian


1 Answers

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>
like image 185
nazim hatipoglu Avatar answered Sep 18 '22 08:09

nazim hatipoglu