ThemeControl.xaml.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using GeekDesk.Constant;
  2. using GeekDesk.Control.Other;
  3. using GeekDesk.Util;
  4. using GeekDesk.ViewModel;
  5. using Microsoft.Win32;
  6. using System;
  7. using System.Collections.ObjectModel;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Input;
  12. namespace GeekDesk.Control.UserControls.Config
  13. {
  14. /// <summary>
  15. /// MotionControl.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class ThemeControl : System.Windows.Controls.UserControl
  18. {
  19. private static AppConfig appConfig = MainWindow.appData.AppConfig;
  20. public ThemeControl()
  21. {
  22. InitializeComponent();
  23. if (appConfig.BGStyle != BGStyle.GradientBac)
  24. {
  25. GradientBGConf.Visibility = Visibility.Collapsed;
  26. ImgBGConf.Visibility = Visibility.Visible;
  27. }
  28. else
  29. {
  30. ImgBGConf.Visibility = Visibility.Collapsed;
  31. GradientBGConf.Visibility = Visibility.Visible;
  32. }
  33. }
  34. /// <summary>
  35. /// 修改背景图片
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. private void BGButton_Click(object sender, RoutedEventArgs e)
  40. {
  41. try
  42. {
  43. OpenFileDialog ofd = new OpenFileDialog
  44. {
  45. Multiselect = false, //只允许选中单个文件
  46. Filter = "图像文件(*.png, *.jpg, *.gif)|*.png;*.jpg;*.gif"
  47. };
  48. if (ofd.ShowDialog() == true)
  49. {
  50. appConfig.BitmapImage = ImageUtil.GetBitmapImageByFile(ofd.FileName);
  51. appConfig.BacImgName = ofd.FileName;
  52. }
  53. }
  54. catch (Exception ex)
  55. {
  56. LogUtil.WriteErrorLog(ex, "修改背景失败,已重置为默认背景!");
  57. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  58. }
  59. BGSettingUtil.BGSetting();
  60. }
  61. private void DefaultButton_Click(object sender, RoutedEventArgs e)
  62. {
  63. try
  64. {
  65. appConfig.BitmapImage = ImageUtil.Base64ToBitmapImage(Constants.DEFAULT_BAC_IMAGE_BASE64);
  66. appConfig.BacImgName = "系统默认";
  67. }
  68. catch (Exception ex)
  69. {
  70. LogUtil.WriteErrorLog(ex, "修改背景失败2,已重置为默认背景!");
  71. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  72. }
  73. BGSettingUtil.BGSetting();
  74. }
  75. private void ColorButton_Click(object sender, RoutedEventArgs e)
  76. {
  77. string tag = (sender as Button).Tag.ToString();
  78. new MyColorPickerDialog(tag, "ConfigWindowDialog");
  79. }
  80. private void PreviewSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  81. {
  82. CheckButtonUpClass cbu = new CheckButtonUpClass
  83. {
  84. e = e
  85. };
  86. System.Threading.ThreadStart ts = new System.Threading.ThreadStart(cbu.CheckButtonUp);
  87. System.Threading.Thread t = new System.Threading.Thread(ts);
  88. t.IsBackground = true;
  89. t.Start();
  90. }
  91. private class CheckButtonUpClass
  92. {
  93. public MouseButtonEventArgs e;
  94. public void CheckButtonUp()
  95. {
  96. while (true)
  97. {
  98. if (e.LeftButton == MouseButtonState.Released)
  99. {
  100. App.Current.Dispatcher.Invoke((Action)(() =>
  101. {
  102. AppData appData = MainWindow.appData;
  103. ObservableCollection<IconInfo> selectIcons = appData.AppConfig.SelectedMenuIcons;
  104. appData.AppConfig.SelectedMenuIcons = null;
  105. appData.AppConfig.SelectedMenuIcons = selectIcons;
  106. }));
  107. return;
  108. }
  109. System.Threading.Thread.Sleep(50);
  110. }
  111. }
  112. }
  113. public void BGStyle_Changed(object sender, RoutedEventArgs e)
  114. {
  115. BGSettingUtil.BGSetting();
  116. if (appConfig.BGStyle != BGStyle.GradientBac)
  117. {
  118. GradientBGConf.Visibility = Visibility.Collapsed;
  119. ImgBGConf.Visibility = Visibility.Visible;
  120. }
  121. else
  122. {
  123. ImgBGConf.Visibility = Visibility.Collapsed;
  124. GradientBGConf.Visibility = Visibility.Visible;
  125. }
  126. }
  127. private void BGOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  128. {
  129. BGSettingUtil.BGSetting();
  130. }
  131. private void Color_TargetUpdated(object sender, DataTransferEventArgs e)
  132. {
  133. BGSettingUtil.BGSetting();
  134. }
  135. private void SysBG_Click(object sender, RoutedEventArgs e)
  136. {
  137. GradientBGDialog gbg = new GradientBGDialog();
  138. gbg.dialog = HandyControl.Controls.Dialog.Show(gbg, "ConfigWindowDialog");
  139. }
  140. private void Animation_Checked(object sender, RoutedEventArgs e)
  141. {
  142. if (MainWindow.mainWindow.Visibility == Visibility.Collapsed)
  143. {
  144. appConfig.IsShow = true;
  145. }
  146. appConfig.IsShow = null;
  147. }
  148. /// <summary>
  149. /// 保存当前颜色到系统预设
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void NewBGBtn_Click(object sender, RoutedEventArgs e)
  154. {
  155. BGNmaeDialog dialog = new BGNmaeDialog();
  156. dialog.dialog = HandyControl.Controls.Dialog.Show(dialog, "ConfigWindowDialog");
  157. }
  158. }
  159. }