好吧,我正在尝试为我的应用程序创建一些自定义外观,而无需创建整个主题。我创建了一个带有默认窗口和以下 App.xaml 的 WPF 4.5 应用程序
<Application x:Class="WpfBGTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="Window">
<Setter Property="Background" Value="Yellow" />
</Style>
</Application.Resources>
</Application>
以及完全默认的窗口代码
<Window x:Class="WpfBGTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
通过这样做,我看到在设计时我的 Window.xaml 是黄色的。但是运行应用程序时,窗口会失去黄色并变回灰色(当前的 Windows 主题?)
这里会发生什么?如何在不将显式静态资源标记放在每个控件上的情况下自定义我的应用程序?我的样式有一个目标类型,没有键。我不明白为什么设计时间与运行时有那么大的不同。
关于合并字典的问题,我已经阅读了足够多的内容,但上面的代码基本上是具有一种风格的香草 WPF 应用程序。
编辑:我使用 Snoop 来查看在决定将获取什么背景时使用了 DefaultStyle。但为什么?观看 Dependecy 属性优先级列表: http: //msdn.microsoft.com/en-us/library/ms743230.aspx我的应用程序样式应该在默认样式之前选择