Files
GeekDesk/Control/Other/IconInfoDialog.xaml.cs

88 lines
2.6 KiB
C#
Raw Normal View History

2022-01-09 16:19:27 +08:00
using GeekDesk.Util;
2021-05-14 16:48:26 +08:00
using GeekDesk.ViewModel;
2022-01-09 16:19:27 +08:00
using Microsoft.Win32;
2021-05-26 17:19:04 +08:00
using System;
2021-05-14 16:48:26 +08:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
2022-01-09 16:17:13 +08:00
2022-01-09 16:19:27 +08:00
namespace GeekDesk.Control.Other
{
2021-05-14 16:48:26 +08:00
/// <summary>
2022-01-09 16:19:27 +08:00
/// TextDialog.xaml 的交互逻辑
2021-05-14 16:48:26 +08:00
/// </summary>
2022-01-09 16:19:27 +08:00
public partial class IconInfoDialog
2021-05-14 16:48:26 +08:00
{
2022-01-09 16:19:27 +08:00
public HandyControl.Controls.Dialog dialog;
public IconInfoDialog()
2021-05-14 16:48:26 +08:00
{
InitializeComponent();
}
2022-01-09 16:19:27 +08:00
public IconInfoDialog(IconInfo info)
2021-05-14 16:48:26 +08:00
{
2022-01-09 16:19:27 +08:00
this.DataContext = info;
InitializeComponent();
2021-05-14 16:48:26 +08:00
}
2022-01-09 16:19:27 +08:00
/// <summary>
/// 保存修改属性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveProperty(object sender, RoutedEventArgs e)
2021-05-14 16:48:26 +08:00
{
2022-01-09 16:19:27 +08:00
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = IconImg.Source as BitmapImage;
info.Name = IconName.Text;
info.AdminStartUp = IconIsAdmin.IsChecked.Value;
info.StartArg = StartArg.Text;
CommonCode.SaveAppData(MainWindow.appData);
dialog.Close();
2021-05-14 16:48:26 +08:00
}
/// <summary>
2022-01-09 16:19:27 +08:00
/// 修改图标为默认
2021-05-14 16:48:26 +08:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2022-01-09 16:19:27 +08:00
private void ReStoreImage(object sender, RoutedEventArgs e)
2021-05-14 16:48:26 +08:00
{
2022-01-09 16:19:27 +08:00
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = ImageUtil.ByteArrToImage(info.DefaultImage);
CommonCode.SaveAppData(MainWindow.appData);
2021-05-14 16:48:26 +08:00
}
/// <summary>
2022-01-09 16:19:27 +08:00
/// 修改图标
2021-05-14 16:48:26 +08:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2022-01-09 16:19:27 +08:00
private void EditImage(object sender, RoutedEventArgs e)
2021-05-14 16:48:26 +08:00
{
2022-01-09 16:19:27 +08:00
try
{
OpenFileDialog ofd = new OpenFileDialog
{
Multiselect = false, //只允许选中单个文件
Filter = "所有文件(*.*)|*.*"
};
if (ofd.ShowDialog() == true)
{
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
CommonCode.SaveAppData(MainWindow.appData);
}
}
catch (Exception e1)
{
HandyControl.Controls.Growl.WarningGlobal("修改图标失败,已重置为默认图标!");
LogUtil.WriteErrorLog(e1, "修改图标失败!");
}
2022-01-09 16:17:13 +08:00
2022-01-09 16:19:27 +08:00
}
2021-05-14 16:48:26 +08:00
}
}