這個工程:
<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