using Common.system; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace XHWK.WKTool.Skin { /// /// 皮肤配置 /// 创建人:赵耀 /// 创建时间:2021年6月18日 /// public class SkinConfig { /// /// 皮肤列表 0白 1蓝 2黑色 /// static List SkinList = new List(); /// /// 初始化皮肤 /// public static void InitSkin() { SkinList.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Skin/SkinDictionary_White.xaml", UriKind.Absolute) }); SkinList.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Skin/SkinDictionary_TechnologyBlue.xaml", UriKind.Absolute) }); int Index = 0; try { Index = int.Parse(APP.SkinStyle); } catch (Exception) {} ChangeSkinResource(SkinList[int.Parse(APP.SkinStyle)]); } /// /// 切换皮肤并保存 0白 1蓝 2黑色 /// /// 0白 1蓝 2黑色 public static void SwitchSkin(int Index) { if (Index < SkinList.Count) { APP.SkinStyle = Index.ToString(); FileToolsCommon.SetConfigValue("SkinStyle", APP.SkinStyle); ChangeSkinResource(SkinList[int.Parse(APP.SkinStyle)]); } } /// /// 更换皮肤资源 /// /// private static void ChangeSkinResource(ResourceDictionary skin) { if(Application.Current.Resources.MergedDictionaries.Count<1) { Application.Current.Resources.MergedDictionaries.Add(skin);//[0] = new ResourceDictionary(); //Application.Current.Resources.MergedDictionaries[0]=skin; } if (Application.Current.Resources.MergedDictionaries[0].Source.IsAbsoluteUri) { if (Application.Current.Resources.MergedDictionaries[0].Source.OriginalString != skin.Source.OriginalString) { Application.Current.Resources.MergedDictionaries[0] = skin; } } else { if (Application.Current.Resources.MergedDictionaries[0].Source.OriginalString.ToString('\\') != skin.Source.OriginalString.ToString('/')) { Application.Current.Resources.MergedDictionaries[0] = skin; } } } } /// /// 扩展方法 /// public static class ExtensionMethod { public static string ToString(this string content, char split) { return content.Split(split).Last(); } } }