效果如下如图:选择皮肤颜色

简单实现WPF界面控件换肤效果

1.首先新建一个如图界面:

选择匹夫下拉框Xaml代码如下:三种颜色选项,并触发SelectionChanged事件

<ComboBox Height="23" Name="comboBox1" Width="120" SelectionChanged="comboBox1_SelectionChanged" IsEditable="False" HorizontalAlignment="Right">
            <ComboBoxItem Content="绿色"/>
            <ComboBoxItem Content="紫色"/>
            <ComboBoxItem Content="灰色"/>
</ComboBox>

 

2.新建三个资源字典文件分别为:

简单实现WPF界面控件换肤效果三种皮肤。

内部代码分别为:

BlueSkin.xaml

 简单实现WPF界面控件换肤效果

GraySkin.xaml

简单实现WPF界面控件换肤效果

PurpleSkin.xaml

简单实现WPF界面控件换肤效果

 

3.触发选择皮肤下拉框的SelectionChanged事件,实现换肤效果,代码如下:

ComboBoxItem cmbItem = comboBox1.SelectedItem as ComboBoxItem;
string item = cmbItem.Content.ToString();
 if (item == "绿色")
 {
             rd.Source = new Uri(@"BlueSkin.xaml", UriKind.Relative);
             Application.Current.Resources = rd;
  }
  if (item == "紫色")
  {
            rd.Source = new Uri(@"PurpleSkin.xaml", UriKind.Relative);
            Application.Current.Resources = rd;
  }
  if (item == "灰色")
  {
            rd.Source = new Uri(@"GraySkin.xaml", UriKind.Relative);
            Application.Current.Resources = rd;
  }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-01-07
  • 2021-08-25
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案