1

我正在尝试应用Windows Presentation Foundation (WPF) CodePlex 项目中的 ExpressionDark 主题。

我已将文件添加到ExpressionDark.xamlThemes文件夹中,并将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}}" />

没有更多的成功。

什么不见​​了?

PS:不知道是否重要,但我窗口的孩子是网格。

4

2 回答 2

3

在 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}">
于 2013-02-13T23:05:46.760 回答
2

上次我检查Window主题中没有样式。

于 2012-07-26T10:49:49.733 回答