ThemeControl.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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)
  53. {
  54. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  55. }
  56. }
  57. private void DefaultButton_Click(object sender, RoutedEventArgs e)
  58. {
  59. try
  60. {
  61. appConfig.BitmapImage = ImageUtil.Base64ToBitmapImage(Constants.DEFAULT_BAC_IMAGE_BASE64);
  62. appConfig.BacImgName = "系统默认";
  63. }
  64. catch (Exception)
  65. {
  66. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  67. }
  68. }
  69. private void ColorButton_Click(object sender, RoutedEventArgs e)
  70. {
  71. ColorPanel.Visibility = Visibility.Visible;
  72. }
  73. private void ColorPicker_Canceled(object sender, EventArgs e)
  74. {
  75. ColorPanel.Visibility = Visibility.Collapsed;
  76. }
  77. private void ColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
  78. {
  79. SolidColorBrush scb = ColorPicker.SelectedBrush;
  80. appConfig.TextColor = scb.ToString();
  81. ColorPanel.Visibility = Visibility.Collapsed;
  82. }
  83. /// <summary>
  84. /// 移动窗口
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  89. {
  90. if (e.LeftButton == MouseButtonState.Pressed)
  91. {
  92. Window.GetWindow(this).DragMove();
  93. }
  94. }
  95. private void PreviewSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  96. {
  97. CheckButtonUpClass cbu = new CheckButtonUpClass
  98. {
  99. e = e
  100. };
  101. System.Threading.ThreadStart ts = new System.Threading.ThreadStart(cbu.CheckButtonUp);
  102. System.Threading.Thread t = new System.Threading.Thread(ts);
  103. t.Start();
  104. }
  105. private class CheckButtonUpClass
  106. {
  107. public MouseButtonEventArgs e;
  108. public void CheckButtonUp()
  109. {
  110. while (true)
  111. {
  112. if (e.LeftButton == MouseButtonState.Released)
  113. {
  114. App.Current.Dispatcher.Invoke((Action)(() =>
  115. {
  116. AppData appData = MainWindow.appData;
  117. ObservableCollection<IconInfo> selectIcons = appData.AppConfig.SelectedMenuIcons;
  118. appData.AppConfig.SelectedMenuIcons = null;
  119. appData.AppConfig.SelectedMenuIcons = selectIcons;
  120. }));
  121. return;
  122. }
  123. System.Threading.Thread.Sleep(50);
  124. }
  125. }
  126. }
  127. }
  128. }