zoukankan      html  css  js  c++  java
  • 简单实现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.新建三个资源字典文件分别为:

    三种皮肤。

    内部代码分别为:

    BlueSkin.xaml

     

    GraySkin.xaml

    PurpleSkin.xaml

    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;
      }

  • 相关阅读:
    OS-lab4
    OS-lab3
    OS-lab2
    OS-lab1
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    HTTP_POST
    实习日志1(2020.7.27-2020.9.31)
    Web app ------ 从Servlet读取Json数据并显示,生成历史数据曲线图
  • 原文地址:https://www.cnblogs.com/_ymw/p/3287874.html
Copyright © 2011-2022 走看看