add:自定义浮动栏图标
This commit is contained in:
@@ -1023,6 +1023,15 @@
|
||||
<ComboBoxItem Content="贴吧滑稽" FontFamily="Microsoft YaHei UI" />
|
||||
</ComboBox>
|
||||
</ui:SimpleStackPanel>
|
||||
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,6,0,0">
|
||||
<TextBlock Foreground="#fafafa" Text="自定义浮动栏图标" VerticalAlignment="Center"
|
||||
FontSize="14" Margin="0,0,16,0" />
|
||||
<Button Name="ButtonAddCustomIcon" Content="上传" FontFamily="Microsoft YaHei UI"
|
||||
Click="ButtonAddCustomIcon_Click" Padding="10,3"/>
|
||||
<Button Name="ButtonManageCustomIcons" Content="管理" FontFamily="Microsoft YaHei UI"
|
||||
Click="ButtonManageCustomIcons_Click" Padding="10,3" Margin="5,0,0,0"/>
|
||||
</ui:SimpleStackPanel>
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<TextBlock Foreground="#fafafa" Text="浮动工具栏缩放" VerticalAlignment="Center"
|
||||
FontSize="14" Margin="0,0,16,0" />
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace Ink_Canvas {
|
||||
|
||||
private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e) {
|
||||
if (!Settings.Advanced.IsEnableResolutionChangeDetection) return;
|
||||
ShowNotification($"检测到显示器信息变化,变为{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height}");
|
||||
ShowNotification($"检测到显示器信息变化,变为{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width}x{System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height})");
|
||||
new Thread(() => {
|
||||
var isFloatingBarOutsideScreen = false;
|
||||
var isInPPTPresentationMode = false;
|
||||
|
||||
@@ -243,41 +243,97 @@ namespace Ink_Canvas {
|
||||
public void ComboBoxFloatingBarImg_SelectionChanged(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
Settings.Appearance.FloatingBarImg = ComboBoxFloatingBarImg.SelectedIndex;
|
||||
if (ComboBoxFloatingBarImg.SelectedIndex == 0) {
|
||||
UpdateFloatingBarIcon();
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
public void UpdateFloatingBarIcon()
|
||||
{
|
||||
int index = Settings.Appearance.FloatingBarImg;
|
||||
|
||||
if (index == 0) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/icc.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(0.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 1) {
|
||||
} else if (index == 1) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(
|
||||
new Uri("pack://application:,,,/Resources/Icons-png/icc-transparent-dark-small.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(1.2);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 2) {
|
||||
} else if (index == 2) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandoujiyanhuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 3) {
|
||||
} else if (index == 3) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanshounvhuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 4) {
|
||||
} else if (index == 4) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanciya.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 5) {
|
||||
} else if (index == 5) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanneikuhuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 6) {
|
||||
} else if (index == 6) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandogeyuanliangwo.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 7) {
|
||||
} else if (index == 7) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/tiebahuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1);
|
||||
} else if (index >= 8 && index - 8 < Settings.Appearance.CustomFloatingBarImgs.Count) {
|
||||
// 使用自定义图标
|
||||
var customIcon = Settings.Appearance.CustomFloatingBarImgs[index - 8];
|
||||
try {
|
||||
FloatingbarHeadIconImg.Source = new BitmapImage(new Uri(customIcon.FilePath));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2);
|
||||
} catch {
|
||||
// 如果加载失败,使用默认图标
|
||||
FloatingbarHeadIconImg.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/icc.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(0.5);
|
||||
}
|
||||
}
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
public void UpdateCustomIconsInComboBox()
|
||||
{
|
||||
// 保留前8个内置图标选项
|
||||
while (ComboBoxFloatingBarImg.Items.Count > 8)
|
||||
{
|
||||
ComboBoxFloatingBarImg.Items.RemoveAt(ComboBoxFloatingBarImg.Items.Count - 1);
|
||||
}
|
||||
|
||||
// 添加自定义图标选项
|
||||
foreach (var customIcon in Settings.Appearance.CustomFloatingBarImgs)
|
||||
{
|
||||
ComboBoxItem item = new ComboBoxItem();
|
||||
item.Content = customIcon.Name;
|
||||
item.FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei UI");
|
||||
ComboBoxFloatingBarImg.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddCustomIcon_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AddCustomIconWindow dialog = new AddCustomIconWindow(this);
|
||||
dialog.Owner = this;
|
||||
dialog.ShowDialog();
|
||||
|
||||
if (dialog.IsSuccess)
|
||||
{
|
||||
// 自动选中新添加的图标
|
||||
ComboBoxFloatingBarImg.SelectedIndex = ComboBoxFloatingBarImg.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonManageCustomIcons_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CustomIconWindow dialog = new CustomIconWindow(this);
|
||||
dialog.Owner = this;
|
||||
dialog.ShowDialog();
|
||||
}
|
||||
|
||||
private void ToggleSwitchEnableTimeDisplayInWhiteboardMode_Toggled(object sender, RoutedEventArgs e) {
|
||||
|
||||
@@ -247,41 +247,20 @@ namespace Ink_Canvas {
|
||||
new SolidColorBrush(StringToColor("#FF555555"));
|
||||
}
|
||||
|
||||
ComboBoxFloatingBarImg.SelectedIndex = Settings.Appearance.FloatingBarImg;
|
||||
if (ComboBoxFloatingBarImg.SelectedIndex == 0) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/icc.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(0.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 1) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(
|
||||
new Uri("pack://application:,,,/Resources/Icons-png/icc-transparent-dark-small.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(1.2);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 2) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandoujiyanhuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 3) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanshounvhuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 4) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanciya.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 5) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuanneikuhuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 6) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/kuandogeyuanliangwo.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1.5);
|
||||
} else if (ComboBoxFloatingBarImg.SelectedIndex == 7) {
|
||||
FloatingbarHeadIconImg.Source =
|
||||
new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/tiebahuaji.png"));
|
||||
FloatingbarHeadIconImg.Margin = new Thickness(2, 2, 2, 1);
|
||||
// 更新自定义图标下拉列表
|
||||
UpdateCustomIconsInComboBox();
|
||||
|
||||
// 设置选中的图标索引
|
||||
// 如果索引超出范围(自定义图标可能已删除),使用默认图标
|
||||
if (Settings.Appearance.FloatingBarImg >= ComboBoxFloatingBarImg.Items.Count)
|
||||
{
|
||||
Settings.Appearance.FloatingBarImg = 0;
|
||||
}
|
||||
|
||||
ComboBoxFloatingBarImg.SelectedIndex = Settings.Appearance.FloatingBarImg;
|
||||
|
||||
// 更新浮动栏图标
|
||||
UpdateFloatingBarIcon();
|
||||
|
||||
ToggleSwitchEnableTimeDisplayInWhiteboardMode.IsOn =
|
||||
Settings.Appearance.EnableTimeDisplayInWhiteboardMode;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
@@ -139,6 +140,8 @@ namespace Ink_Canvas
|
||||
public double ViewboxFloatingBarScaleTransformValue { get; set; } = 1.0;
|
||||
[JsonProperty("floatingBarImg")]
|
||||
public int FloatingBarImg { get; set; } = 0;
|
||||
[JsonProperty("customFloatingBarImgs")]
|
||||
public List<CustomFloatingBarIcon> CustomFloatingBarImgs { get; set; } = new List<CustomFloatingBarIcon>();
|
||||
[JsonProperty("viewboxFloatingBarOpacityValue")]
|
||||
public double ViewboxFloatingBarOpacityValue { get; set; } = 1.0;
|
||||
[JsonProperty("enableTrayIcon")]
|
||||
@@ -438,4 +441,22 @@ namespace Ink_Canvas
|
||||
[JsonProperty("directCallCiRand")]
|
||||
public bool DirectCallCiRand { get; set; } = false;
|
||||
}
|
||||
|
||||
public class CustomFloatingBarIcon
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("filePath")]
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public CustomFloatingBarIcon(string name, string filePath)
|
||||
{
|
||||
Name = name;
|
||||
FilePath = filePath;
|
||||
}
|
||||
|
||||
// 用于JSON序列化
|
||||
public CustomFloatingBarIcon() { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<Window x:Class="Ink_Canvas.AddCustomIconWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:local="clr-namespace:Ink_Canvas"
|
||||
mc:Ignorable="d"
|
||||
Title="添加自定义图标" Height="500" Width="750" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="添加自定义浮动栏图标" FontSize="18" FontWeight="Bold" Margin="0,0,0,15" Grid.Row="0"/>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,0,20">
|
||||
<TextBlock Text="选择图标文件:" VerticalAlignment="Center" FontSize="14"/>
|
||||
<TextBox Name="IconPathTextBox" Width="220" IsReadOnly="True" Margin="10,0" Height="25"/>
|
||||
<Button Content="浏览..." Click="BrowseButton_Click" Width="80" Height="45"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,0,0,20">
|
||||
<TextBlock Text="图标名称:" VerticalAlignment="Center" FontSize="14"/>
|
||||
<TextBox Name="IconNameTextBox" Width="280" Margin="28,0,0,0" Height="25"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="3" Text="预览:" Margin="0,0,0,8" FontSize="14"/>
|
||||
|
||||
<Border Grid.Row="4" BorderBrush="#CCCCCC" BorderThickness="1" Padding="8" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<Image Name="IconPreviewImage" Width="72" Height="72" Stretch="Uniform"/>
|
||||
</Border>
|
||||
|
||||
<StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,25,0,0">
|
||||
<Button Content="取消" Width="100" Height="30" Click="CancelButton_Click" Margin="0,0,15,0"/>
|
||||
<Button Name="SaveButton" Content="保存" Width="100" Height="30" Click="SaveButton_Click" IsEnabled="False"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
/// <summary>
|
||||
/// AddCustomIconWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class AddCustomIconWindow : Window
|
||||
{
|
||||
private MainWindow mainWindow;
|
||||
private string selectedFilePath;
|
||||
public bool IsSuccess { get; private set; }
|
||||
|
||||
public AddCustomIconWindow(MainWindow owner)
|
||||
{
|
||||
InitializeComponent();
|
||||
mainWindow = owner;
|
||||
IsSuccess = false;
|
||||
|
||||
// 添加TextBox内容变化事件以检查是否可以保存
|
||||
IconNameTextBox.TextChanged += (s, e) => ValidateSaveButton();
|
||||
}
|
||||
|
||||
private void BrowseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "图像文件|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.ico",
|
||||
Title = "选择一个图标文件"
|
||||
};
|
||||
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
selectedFilePath = openFileDialog.FileName;
|
||||
IconPathTextBox.Text = selectedFilePath;
|
||||
|
||||
// 显示预览
|
||||
try
|
||||
{
|
||||
BitmapImage bitmap = new BitmapImage();
|
||||
bitmap.BeginInit();
|
||||
bitmap.UriSource = new Uri(selectedFilePath);
|
||||
bitmap.EndInit();
|
||||
IconPreviewImage.Source = bitmap;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"无法加载图像: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
// 自动填充名称建议(文件名,不包括扩展名)
|
||||
string suggestedName = Path.GetFileNameWithoutExtension(selectedFilePath);
|
||||
IconNameTextBox.Text = suggestedName;
|
||||
|
||||
ValidateSaveButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateSaveButton()
|
||||
{
|
||||
SaveButton.IsEnabled = !string.IsNullOrWhiteSpace(IconNameTextBox.Text) && !string.IsNullOrEmpty(selectedFilePath);
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建pictures文件夹(如果不存在)
|
||||
string picturesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pictures");
|
||||
if (!Directory.Exists(picturesFolder))
|
||||
{
|
||||
Directory.CreateDirectory(picturesFolder);
|
||||
}
|
||||
|
||||
// 生成一个唯一的文件名(使用GUID)
|
||||
string extension = Path.GetExtension(selectedFilePath);
|
||||
string newFileName = $"{Guid.NewGuid()}{extension}";
|
||||
string destPath = Path.Combine(picturesFolder, newFileName);
|
||||
|
||||
// 复制文件到pictures文件夹
|
||||
File.Copy(selectedFilePath, destPath);
|
||||
|
||||
// 创建新的自定义图标对象
|
||||
var customIcon = new CustomFloatingBarIcon(IconNameTextBox.Text, destPath);
|
||||
|
||||
// 添加到主窗口的设置中
|
||||
MainWindow.Settings.Appearance.CustomFloatingBarImgs.Add(customIcon);
|
||||
|
||||
// 更新ComboBox
|
||||
mainWindow.UpdateCustomIconsInComboBox();
|
||||
|
||||
// 保存设置
|
||||
MainWindow.SaveSettingsToFile();
|
||||
|
||||
IsSuccess = true;
|
||||
this.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"保存图标时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<Window x:Class="Ink_Canvas.CustomIconWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:local="clr-namespace:Ink_Canvas"
|
||||
mc:Ignorable="d"
|
||||
Title="自定义浮动栏图标" Height="450" Width="500" WindowStartupLocation="CenterScreen">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="自定义浮动栏图标管理" FontSize="20" FontWeight="Bold" Margin="0,0,0,15"/>
|
||||
|
||||
<ListView Grid.Row="1" Name="CustomIconsListView" BorderBrush="#CCCCCC" BorderThickness="1">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="预览" Width="80">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Image Source="{Binding FilePath}" Width="32" Height="32"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="名称" Width="200" DisplayMemberBinding="{Binding Name}"/>
|
||||
<GridViewColumn Header="操作" Width="100">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="删除" Click="DeleteCustomIcon_Click" Tag="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,15,0,0">
|
||||
<Button Content="关闭" Width="80" Click="CloseButton_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
/// <summary>
|
||||
/// CustomIconWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class CustomIconWindow : Window
|
||||
{
|
||||
private MainWindow mainWindow;
|
||||
public ObservableCollection<CustomFloatingBarIcon> CustomIcons { get; set; }
|
||||
|
||||
public CustomIconWindow(MainWindow owner)
|
||||
{
|
||||
InitializeComponent();
|
||||
mainWindow = owner;
|
||||
|
||||
// 从主窗口的设置获取自定义图标列表
|
||||
CustomIcons = new ObservableCollection<CustomFloatingBarIcon>(MainWindow.Settings.Appearance.CustomFloatingBarImgs);
|
||||
CustomIconsListView.ItemsSource = CustomIcons;
|
||||
}
|
||||
|
||||
private void DeleteCustomIcon_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button button && button.Tag is CustomFloatingBarIcon icon)
|
||||
{
|
||||
// 从列表中移除图标
|
||||
CustomIcons.Remove(icon);
|
||||
|
||||
// 更新主窗口的设置
|
||||
MainWindow.Settings.Appearance.CustomFloatingBarImgs.Clear();
|
||||
foreach (var customIcon in CustomIcons)
|
||||
{
|
||||
MainWindow.Settings.Appearance.CustomFloatingBarImgs.Add(customIcon);
|
||||
}
|
||||
|
||||
// 如果当前选中的是被删除的图标,重置为默认图标
|
||||
if (MainWindow.Settings.Appearance.FloatingBarImg >= 8 &&
|
||||
MainWindow.Settings.Appearance.FloatingBarImg - 8 >= MainWindow.Settings.Appearance.CustomFloatingBarImgs.Count)
|
||||
{
|
||||
MainWindow.Settings.Appearance.FloatingBarImg = 0;
|
||||
mainWindow.ComboBoxFloatingBarImg.SelectedIndex = 0;
|
||||
mainWindow.UpdateFloatingBarIcon();
|
||||
}
|
||||
|
||||
// 更新ComboBox
|
||||
mainWindow.UpdateCustomIconsInComboBox();
|
||||
|
||||
// 保存设置
|
||||
MainWindow.SaveSettingsToFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user