开发者

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

开发者 https://www.devze.com 2023-02-21 10:20 出处:网络
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\

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 r开发者_Python百科uns fine, but I prefer to not have any compilation warnings when compiling.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号