这个工程:
<Window x:Class="Moria.Net.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
x:Name="window"
Background="{DynamicResource WindowBrush}"
Width="800" Height="600">
<Window.Resources>
<SolidColorBrush x:Key="WindowBrush" Color="LightGray"/>
</Window.Resources>
</Window>
这里要注意的主要事情是x:名称窗口,并在后台财产
alternativly的DynamicResource ,这也适用于......
<Window.Resources>
<SolidColorBrush x:Key="WindowBrush" Color="LightGray"/>
</Window.Resources>
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="{StaticResource WindowBrush}"/>
</Style>
</Window.Style>
作为一个方面,如果你想使用主题为你的应用程序,你应该看看component resource keys
一个解决方案,但不是解决方案。对于涉及多个项目的应用程序(如Prism应用程序)来说这不太合适。 – 2010-01-20 14:58:48