Files
GeekDesk/Control/UserControls/Config/ThemeControl.xaml.cs

183 lines
5.9 KiB
C#
Raw Normal View History

using GeekDesk.Constant;
2022-05-10 15:33:06 +08:00
using GeekDesk.Control.Other;
using GeekDesk.Util;
2021-05-26 17:19:04 +08:00
using GeekDesk.ViewModel;
using Microsoft.Win32;
2021-05-20 17:33:49 +08:00
using System;
using System.Collections.ObjectModel;
2021-05-20 17:33:49 +08:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace GeekDesk.Control.UserControls.Config
2021-05-20 17:33:49 +08:00
{
2022-05-09 15:25:48 +08:00
2021-05-20 17:33:49 +08:00
/// <summary>
2021-05-31 17:31:16 +08:00
/// MotionControl.xaml 的交互逻辑
2021-05-20 17:33:49 +08:00
/// </summary>
2021-05-31 17:31:16 +08:00
public partial class ThemeControl : System.Windows.Controls.UserControl
2021-05-20 17:33:49 +08:00
{
private static AppConfig appConfig = MainWindow.appData.AppConfig;
2022-03-25 17:57:01 +08:00
2021-05-31 17:31:16 +08:00
public ThemeControl()
2021-05-20 17:33:49 +08:00
{
2021-05-20 17:33:49 +08:00
InitializeComponent();
2022-05-09 15:25:48 +08:00
if (appConfig.BGStyle != BGStyle.GradientBac)
{
GradientBGConf.Visibility = Visibility.Collapsed;
ImgBGConf.Visibility = Visibility.Visible;
}
else
{
ImgBGConf.Visibility = Visibility.Collapsed;
GradientBGConf.Visibility = Visibility.Visible;
}
2021-05-20 17:33:49 +08:00
}
2021-05-26 17:19:04 +08:00
/// <summary>
/// 修改背景图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BGButton_Click(object sender, RoutedEventArgs e)
2021-05-21 17:19:46 +08:00
{
2022-03-25 17:57:01 +08:00
2021-05-26 17:19:04 +08:00
try
{
OpenFileDialog ofd = new OpenFileDialog
{
Multiselect = false, //只允许选中单个文件
Filter = "图像文件(*.png, *.jpg, *.gif)|*.png;*.jpg;*.gif"
2021-05-26 17:19:04 +08:00
};
if (ofd.ShowDialog() == true)
{
appConfig.BitmapImage = ImageUtil.GetBitmapImageByFile(ofd.FileName);
2021-05-28 18:01:19 +08:00
appConfig.BacImgName = ofd.FileName;
2021-05-26 17:19:04 +08:00
}
2021-05-31 17:31:16 +08:00
}
2022-01-09 17:33:49 +08:00
catch (Exception ex)
2021-05-26 17:19:04 +08:00
{
2022-01-09 17:33:49 +08:00
LogUtil.WriteErrorLog(ex, "修改背景失败,已重置为默认背景!");
2021-05-26 17:19:04 +08:00
HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
}
2022-05-09 15:25:48 +08:00
BGSettingUtil.BGSetting();
2021-05-21 17:19:46 +08:00
}
private void DefaultButton_Click(object sender, RoutedEventArgs e)
{
try
{
appConfig.BitmapImage = ImageUtil.Base64ToBitmapImage(Constants.DEFAULT_BAC_IMAGE_BASE64);
appConfig.BacImgName = "系统默认";
}
2022-01-09 17:33:49 +08:00
catch (Exception ex)
{
2022-01-09 17:33:49 +08:00
LogUtil.WriteErrorLog(ex, "修改背景失败2,已重置为默认背景!");
HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
}
2022-05-09 15:25:48 +08:00
BGSettingUtil.BGSetting();
}
private void ColorButton_Click(object sender, RoutedEventArgs e)
{
2022-05-09 15:25:48 +08:00
string tag = (sender as Button).Tag.ToString();
new MyColorPickerDialog(tag, "ConfigWindowDialog");
}
private void PreviewSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
CheckButtonUpClass cbu = new CheckButtonUpClass
{
e = e
};
System.Threading.ThreadStart ts = new System.Threading.ThreadStart(cbu.CheckButtonUp);
System.Threading.Thread t = new System.Threading.Thread(ts);
t.IsBackground = true;
t.Start();
}
private class CheckButtonUpClass
{
public MouseButtonEventArgs e;
public void CheckButtonUp()
{
while (true)
{
if (e.LeftButton == MouseButtonState.Released)
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
AppData appData = MainWindow.appData;
ObservableCollection<IconInfo> selectIcons = appData.AppConfig.SelectedMenuIcons;
appData.AppConfig.SelectedMenuIcons = null;
appData.AppConfig.SelectedMenuIcons = selectIcons;
}));
return;
}
System.Threading.Thread.Sleep(50);
}
}
}
2022-03-25 17:57:01 +08:00
2022-05-09 15:25:48 +08:00
public void BGStyle_Changed(object sender, RoutedEventArgs e)
{
BGSettingUtil.BGSetting();
if (appConfig.BGStyle != BGStyle.GradientBac)
{
GradientBGConf.Visibility = Visibility.Collapsed;
ImgBGConf.Visibility = Visibility.Visible;
}
else
2022-05-09 15:25:48 +08:00
{
ImgBGConf.Visibility = Visibility.Collapsed;
GradientBGConf.Visibility = Visibility.Visible;
}
}
private void BGOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
BGSettingUtil.BGSetting();
}
2022-03-25 17:57:01 +08:00
2022-05-09 15:25:48 +08:00
private void Color_TargetUpdated(object sender, DataTransferEventArgs e)
{
BGSettingUtil.BGSetting();
}
2022-05-10 15:33:06 +08:00
private void SysBG_Click(object sender, RoutedEventArgs e)
{
GradientBGDialog gbg = new GradientBGDialog();
gbg.dialog = HandyControl.Controls.Dialog.Show(gbg, "ConfigWindowDialog");
2022-05-10 15:33:06 +08:00
}
2022-06-14 10:37:24 +08:00
private void Animation_Checked(object sender, RoutedEventArgs e)
{
if (MainWindow.mainWindow.Visibility == Visibility.Collapsed)
{
appConfig.IsShow = true;
}
appConfig.IsShow = null;
}
2025-03-07 10:59:39 +08:00
/// <summary>
/// 保存当前颜色到系统预设
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NewBGBtn_Click(object sender, RoutedEventArgs e)
{
BGNmaeDialog dialog = new BGNmaeDialog();
dialog.dialog = HandyControl.Controls.Dialog.Show(dialog, "ConfigWindowDialog");
}
2021-05-20 17:33:49 +08:00
}
}