[WPF]颜色主题功能

效果

 [WPF]颜色主题功能_第1张图片

[WPF]颜色主题功能_第2张图片

[WPF]颜色主题功能_第3张图片

点击选择皮肤颜色

 

代码

 public enum Themes
    {
        Blue,
        Gray,
        Orange
    }
    /// 
    /// 主题颜色管理类
    /// 
    public static class ThemeAssist
    {


        /// 
        /// 改变主题颜色
        /// 
        /// 
        public static void ChangeTheme(Themes themeName)
        {
            var mergedDictionaries = Application.Current.Resources.MergedDictionaries;

            foreach (var merged in mergedDictionaries)
            {
                if (merged.Source.ToString().Contains(nameof(Themes.Orange)) 
                    || merged.Source.ToString().Contains(nameof(Themes.Gray))
                    || merged.Source.ToString().Contains(nameof(Themes.Blue)))
                {
                    mergedDictionaries.Remove(merged);
                    break;
                }
            }
            mergedDictionaries.Add(new ResourceDictionary { Source = new Uri($"pack://application:,,,/StikyNotes;component/Style/Themes/{themeName.ToString()}.xaml") });
        }

    }

 

项目地址(源码)

https://github.com/li-zheng-hao/StikyNotes 

你可能感兴趣的:(WPF,WPF自制便签软件)