我正在尝试应用Windows Presentation Foundation(WPF)CodePlex项目中的ExpressionDark主题。
我在Themes
子文件夹中添加了文件ExpressionDark.xaml
,并将我的App.xaml
文件更改为引用此文件:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Themes/ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
运行程序时,样式应用于所有控件,但不应用于窗口本身。窗口的背景保持为白色。我所理解的是,样式适用于Window
类,但不适用于派生类。
为了解决这个问题,我尝试在app.xaml
文件中创建一个新样式,以便继承我的自定义窗口类的Windows样式:
<Application.Resources>
<ResourceDictionary>
<Style
TargetType="{x:Type local:MainWindow}"
BasedOn="{StaticResource {x:Type Window}}" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Themes/ExpressionDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
结果完全相同。
我也尝试了WPF的建议:主题冒险(第2部分)。我添加到我的窗口定义:
<Window
x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MyProject.ViewModel"
Title="MainWindow"
Height="350"
Width="525"
Style="{DynamicResource {x:Type Window}}" />
没有更多的成功。
缺少什么?
附言:不知道这是否重要,但我窗户的孩子是网格。
使用窗口XAML 中的动态资源指定背景
<Window x:Class="HellowWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hellow World" Height="614" Width="821"
Background="{DynamicResource WindowBackgroundBrush}">
上次检查主题中没有Window
样式。