ResourceDictionary 中的 Windows 样式不适用 [英] Windows Style from ResourceDictionary don't apply
本文介绍了ResourceDictionary 中的 Windows 样式不适用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于我的应用程序中有多个 Window
,我正在寻找一种不需要我在每个 Window上设置
binding
的解决方案代码>.
As I have multiple Window
s in my application, I am looking for a solution that does not require me to set a binding
on each Window
.
我创建了一个 ResourceDictionary
,它有一个 style
用于窗口背景:
I created a ResourceDictionary
which has a style
for the Window Background:
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="AliceBlue"/>
</Style>
在我的 XAML
中,我设置了 ResourceDictionary
:
In my XAML
, I set the ResourceDictionary
:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
没有错误,但我的 Window
颜色保持白色.
There is no error, but my Window
color stays white.
推荐答案
在资源字典中添加新画笔
Add a new brush in your resource dictionary
<SolidColorBrush x:Key="WindowBackground" Color="AliceBlue" />
并在您的 WPF 窗口中简单地将所需资源设置为窗口背景属性
and in your WPF window simply set the required resource to the window background property
<Window x:Class="GDD.Presentation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300"
Background="{StaticResource WindowBackground}">
这篇关于ResourceDictionary 中的 Windows 样式不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文