星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SkinConfig.cs 3.1KB

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