【发布时间】:2013-03-03 22:22:15
【问题描述】:
由于我的应用程序中有多个Windows,我正在寻找一种不需要我在每个Window 上设置binding 的解决方案。
我为窗口背景创建了一个ResourceDictionary,其中有一个style:
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="AliceBlue"/>
</Style>
在我的XAML 中,我设置了ResourceDictionary:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
没有错误,但我的Window 颜色保持白色。
【问题讨论】:
-
请尝试 Application.Resources 而不是 Window.Resources
-
您的
ResourceDictionaryxaml 文件是否在项目的根文件夹中? -
@LPL:它应该仍然可以在
Windows.Resources中工作。 -
@Dan 你确定吗? AFAIK 资源只影响孩子而不是他们自己,不是吗?
-
我试图在 Application.Resources 中移动它(在 App.xaml 中):没有变化!