WPF 动态资源 : Warning Message - "The resource ' resource' could not be resolved."

标签 wpf xaml compiler-warnings suppress-warnings dynamicresource

基本上,我有一个使用 DynamicResources 的 UserControl。应用程序使用该资源编译并运行良好,但看到此警告消息有点烦人。这让我怀疑我是否做对了,这只是一个误报,还是我做错了,碰巧从工作的裂缝中溜走了。

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

所以,如果我正确使用它,我怎样才能摆脱这个警告信息?
如果我没有正确使用它,它应该是什么样子,这样我就不会收到警告?

附言我的应用程序工作正常,但我更喜欢在编译时没有任何编译警告。

最佳答案

你可以像这样映射你的资源

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

Theme.xaml 必须包含 'AppDefaultBackgroundColor' 像这样
 <Color x:Key="AppDefaultBackgroundColor">#FF77C6FB</Color>

关于WPF 动态资源 : Warning Message - "The resource ' resource' could not be resolved.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5505746/

相关文章:

c - 消除一段代码中未使用的静态函数警告

c# - 为什么这个程序只产生三个警告?

WPF - 基于内容突出显示文本框

wpf - 为用户控件定义 View 模型的类型,然后从父控件处理它

.net - http ://schemas. microsoft.com/winfx/2006/xaml/presentation 的架构文件的位置在哪里?

c# - 如何在 UWP (Windows 10) 中更改所选 ListView 项目的突出显示颜色

java - Eclipse 警告 Uncaught Error

wpf - 如何使用 Unity 和 MVVM 在 WPF 应用程序中切换 View ?

wpf - 底部垂直滚动richtextbox [WPF]

c# - 来自 Binding ElementName 的值生成空字符串