创建一个项目主题资源字典并将引用FooTheme.xaml
放入其中。
在项目的所有窗口中,引用ProjectTheme.xaml
.
这样,为了改变项目的主题,你只需要修改一行。
代码:
FooTheme.xaml(示例主题)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button">
<Setter Property="Background" Value="Blue"/>
</Style>
</ResourceDictionary>
ProjectTheme.xaml(项目主题)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- In order to modify the project's theme, change this line -->
<ResourceDictionary Source="FooTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
MainWindow.xaml(示例项目窗口)
<Window x:Class="So17372811ProjectTheme.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">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ProjectTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button Content="Click me!"/>
</Grid>
</Window>