星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SkinConfig.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. namespace XHWK.WKTool.Skin
  9. {
  10. using system;
  11. /// <summary>
  12. /// 皮肤配置
  13. /// 创建人:赵耀
  14. /// 创建时间:2021年6月18日
  15. /// </summary>
  16. public class SkinConfig
  17. {
  18. /// <summary>
  19. /// 皮肤列表 0白 1蓝 2黑色
  20. /// </summary>
  21. static List<ResourceDictionary> SkinList = new List<ResourceDictionary>();
  22. /// <summary>
  23. /// 初始化皮肤
  24. /// </summary>
  25. public static void InitSkin()
  26. {
  27. SkinList.Add(new ResourceDictionary()
  28. {
  29. Source = new Uri("pack://application:,,,/Skin/SkinDictionary_White.xaml", UriKind.Absolute)
  30. });
  31. SkinList.Add(new ResourceDictionary()
  32. {
  33. Source = new Uri("pack://application:,,,/Skin/SkinDictionary_TechnologyBlue.xaml", UriKind.Absolute)
  34. });
  35. int Index = 0;
  36. try
  37. {
  38. Index = int.Parse(App.SkinStyle);
  39. }
  40. catch (Exception) { }
  41. ChangeSkinResource(SkinList[int.Parse(App.SkinStyle)]);
  42. }
  43. /// <summary>
  44. /// 切换皮肤并保存 0白 1蓝 2黑色
  45. /// </summary>
  46. /// <param name="Index"> 0白 1蓝 2黑色</param>
  47. public static void SwitchSkin(int Index)
  48. {
  49. if (Index < SkinList.Count)
  50. {
  51. App.SkinStyle = Index.ToString();
  52. FileToolsCommon.SetConfigValue("SkinStyle", App.SkinStyle);
  53. ChangeSkinResource(SkinList[int.Parse(App.SkinStyle)]);
  54. }
  55. }
  56. /// <summary>
  57. /// 更换皮肤资源
  58. /// </summary>
  59. /// <param name="skin"></param>
  60. private static void ChangeSkinResource(ResourceDictionary skin)
  61. {
  62. if(Application.Current.Resources.MergedDictionaries.Count<1)
  63. {
  64. Application.Current.Resources.MergedDictionaries.Add(skin);//[0] = new ResourceDictionary();
  65. //Application.Current.Resources.MergedDictionaries[0]=skin;
  66. }
  67. if (Application.Current.Resources.MergedDictionaries[0].Source.IsAbsoluteUri)
  68. {
  69. if (Application.Current.Resources.MergedDictionaries[0].Source.OriginalString != skin.Source.OriginalString)
  70. {
  71. Application.Current.Resources.MergedDictionaries[0] = skin;
  72. }
  73. }
  74. else
  75. {
  76. if (Application.Current.Resources.MergedDictionaries[0].Source.OriginalString.ToString('\\') != skin.Source.OriginalString.ToString('/'))
  77. {
  78. Application.Current.Resources.MergedDictionaries[0] = skin;
  79. }
  80. }
  81. }
  82. }
  83. /// <summary>
  84. /// 扩展方法
  85. /// </summary>
  86. public static class ExtensionMethod
  87. {
  88. public static string ToString(this string content, char split)
  89. {
  90. return content.Split(split).Last();
  91. }
  92. }
  93. }