1、创建资源字典
2、添加颜色资源,这里分别是白色和黑色,分为两个资源字典white.xaml和Black.xaml
<SolidColorBrush x:Key="WindowBrush" Color="#252525"></SolidColorBrush>
<SolidColorBrush x:Key="WindowBrush" Color="#ffffff"></SolidColorBrush>
3、前台使用需要引用
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Black.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
调用:
Background="{DynamicResource WindowBrush}
4、切换颜色(皮肤)
this.Resources = new ResourceDictionary()
{
Source = new Uri("pack://Application:,,,/White.xaml")
// Source = new Uri("pack://Application:,,,/Black.xaml")
};