add:新设置

This commit is contained in:
2026-02-06 22:01:01 +08:00
parent 15a6799d7b
commit b2648fecac
@@ -1,7 +1,9 @@
using System; using System;
using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Ink_Canvas.Windows.SettingsViews; using Ink_Canvas.Windows.SettingsViews;
using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews namespace Ink_Canvas.Windows.SettingsViews
{ {
@@ -90,19 +92,17 @@ namespace Ink_Canvas.Windows.SettingsViews
{ {
try try
{ {
var border = FindName(name) as System.Windows.Controls.Border; var border = FindName(name) as Border;
if (border != null) if (border == null) return;
border.Background = isOn
? new SolidColorBrush(Color.FromRgb(0x35, 0x84, 0xE4))
: new SolidColorBrush(Color.FromRgb(0xE1, 0xE1, 0xE1));
var innerBorder = border.Child as Border;
if (innerBorder != null)
{ {
bool currentState = border.Background.ToString().Contains("3584e4"); innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
if (currentState != isOn)
{
border.Background = isOn ? new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0x35, 0x84, 0xe4)) : new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0xe1, 0xe1, 0xe1));
var innerBorder = border.Child as System.Windows.Controls.Border;
if (innerBorder != null)
{
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
}
}
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -111,6 +111,27 @@ namespace Ink_Canvas.Windows.SettingsViews
} }
} }
private static bool IsToggleSwitchOn(Border border)
{
try
{
if (border?.Background is SolidColorBrush scb)
{
return scb.Color.A == 0xFF &&
scb.Color.R == 0x35 &&
scb.Color.G == 0x84 &&
scb.Color.B == 0xE4;
}
var s = border?.Background?.ToString();
return string.Equals(s, "#FF3584E4", StringComparison.OrdinalIgnoreCase);
}
catch
{
return false;
}
}
/// <summary> /// <summary>
/// ToggleSwitch 点击事件处理 /// ToggleSwitch 点击事件处理
/// </summary> /// </summary>
@@ -118,11 +139,10 @@ namespace Ink_Canvas.Windows.SettingsViews
{ {
if (!_isLoaded) return; if (!_isLoaded) return;
var border = sender as System.Windows.Controls.Border; var border = sender as Border;
if (border == null) return; if (border == null) return;
bool currentState = border.Background.ToString().Contains("3584e4"); bool newState = !IsToggleSwitchOn(border);
bool newState = !currentState;
SetToggleSwitchState(border.Name, newState); SetToggleSwitchState(border.Name, newState);
// 通过 MainWindowSettingsHelper 调用 MainWindow 中的方法 // 通过 MainWindowSettingsHelper 调用 MainWindow 中的方法