ThemeControl.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using GeekDesk.Constant;
  2. using GeekDesk.Util;
  3. using GeekDesk.ViewModel;
  4. using Microsoft.Win32;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace GeekDesk.Control.UserControls.Config
  21. {
  22. /// <summary>
  23. /// MotionControl.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class ThemeControl : System.Windows.Controls.UserControl
  26. {
  27. private static AppConfig appConfig = MainWindow.appData.AppConfig;
  28. public ThemeControl()
  29. {
  30. InitializeComponent();
  31. }
  32. /// <summary>
  33. /// 修改背景图片
  34. /// </summary>
  35. /// <param name="sender"></param>
  36. /// <param name="e"></param>
  37. private void BGButton_Click(object sender, RoutedEventArgs e)
  38. {
  39. try
  40. {
  41. OpenFileDialog ofd = new OpenFileDialog
  42. {
  43. Multiselect = false, //只允许选中单个文件
  44. Filter = "图像文件(*.png, *.jpg)|*.png;*.jpg;*.gif"
  45. };
  46. if (ofd.ShowDialog() == true)
  47. {
  48. appConfig.BitmapImage = ImageUtil.GetBitmapImageByFile(ofd.FileName);
  49. appConfig.BacImgName = ofd.FileName;
  50. }
  51. }
  52. catch (Exception ex)
  53. {
  54. LogUtil.WriteErrorLog(ex, "修改背景失败,已重置为默认背景!");
  55. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  56. }
  57. }
  58. private void DefaultButton_Click(object sender, RoutedEventArgs e)
  59. {
  60. try
  61. {
  62. appConfig.BitmapImage = ImageUtil.Base64ToBitmapImage(Constants.DEFAULT_BAC_IMAGE_BASE64);
  63. appConfig.BacImgName = "系统默认";
  64. }
  65. catch (Exception ex)
  66. {
  67. LogUtil.WriteErrorLog(ex, "修改背景失败2,已重置为默认背景!");
  68. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  69. }
  70. }
  71. private void ColorButton_Click(object sender, RoutedEventArgs e)
  72. {
  73. ColorPanel.Visibility = Visibility.Visible;
  74. }
  75. private void ColorPicker_Canceled(object sender, EventArgs e)
  76. {
  77. ColorPanel.Visibility = Visibility.Collapsed;
  78. }
  79. private void ColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
  80. {
  81. SolidColorBrush scb = ColorPicker.SelectedBrush;
  82. appConfig.TextColor = scb.ToString();
  83. ColorPanel.Visibility = Visibility.Collapsed;
  84. }
  85. /// <summary>
  86. /// 移动窗口
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  91. {
  92. if (e.LeftButton == MouseButtonState.Pressed)
  93. {
  94. Window.GetWindow(this).DragMove();
  95. }
  96. }
  97. private void PreviewSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  98. {
  99. CheckButtonUpClass cbu = new CheckButtonUpClass
  100. {
  101. e = e
  102. };
  103. System.Threading.ThreadStart ts = new System.Threading.ThreadStart(cbu.CheckButtonUp);
  104. System.Threading.Thread t = new System.Threading.Thread(ts);
  105. t.Start();
  106. }
  107. private class CheckButtonUpClass
  108. {
  109. public MouseButtonEventArgs e;
  110. public void CheckButtonUp()
  111. {
  112. while (true)
  113. {
  114. if (e.LeftButton == MouseButtonState.Released)
  115. {
  116. App.Current.Dispatcher.Invoke((Action)(() =>
  117. {
  118. AppData appData = MainWindow.appData;
  119. ObservableCollection<IconInfo> selectIcons = appData.AppConfig.SelectedMenuIcons;
  120. appData.AppConfig.SelectedMenuIcons = null;
  121. appData.AppConfig.SelectedMenuIcons = selectIcons;
  122. }));
  123. return;
  124. }
  125. System.Threading.Thread.Sleep(50);
  126. }
  127. }
  128. }
  129. }
  130. }