优化代码
This commit is contained in:
@@ -299,8 +299,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
// 获取主窗口实例并清理PowerPoint进程守护
|
||||
var mainWindow = Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null)
|
||||
if (Current.MainWindow is MainWindow mainWindow)
|
||||
{
|
||||
// 通过反射调用StopPowerPointProcessMonitoring方法
|
||||
var method = mainWindow.GetType().GetMethod("StopPowerPointProcessMonitoring",
|
||||
|
||||
@@ -30,8 +30,7 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
if (!(bool)window.GetValue(IsAvoidFullScreenEnabledProperty))
|
||||
{
|
||||
var hwndSource = PresentationSource.FromVisual(window) as HwndSource;
|
||||
if (hwndSource != null)
|
||||
if (PresentationSource.FromVisual(window) is HwndSource hwndSource)
|
||||
{
|
||||
hwndSource.AddHook(KeepInWorkingAreaHook);
|
||||
window.SetValue(IsAvoidFullScreenEnabledProperty, true);
|
||||
@@ -46,8 +45,7 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
if ((bool)window.GetValue(IsAvoidFullScreenEnabledProperty))
|
||||
{
|
||||
var hwndSource = PresentationSource.FromVisual(window) as HwndSource;
|
||||
if (hwndSource != null)
|
||||
if (PresentationSource.FromVisual(window) is HwndSource hwndSource)
|
||||
{
|
||||
hwndSource.RemoveHook(KeepInWorkingAreaHook);
|
||||
window.ClearValue(IsAvoidFullScreenEnabledProperty);
|
||||
@@ -61,8 +59,7 @@ namespace Ink_Canvas.Helpers
|
||||
private static IntPtr KeepInWorkingAreaHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
// 只拦截主画布窗口的全屏(最大化)操作
|
||||
var window = HwndSource.FromHwnd(hwnd)?.RootVisual as Window;
|
||||
if (window == null) return IntPtr.Zero;
|
||||
if (!(HwndSource.FromHwnd(hwnd)?.RootVisual is Window window)) return IntPtr.Zero;
|
||||
// 这里假设主画布窗口类名为MainWindow(如有不同请调整)
|
||||
if (window.GetType().Name != "MainWindow") return IntPtr.Zero;
|
||||
|
||||
|
||||
@@ -112,8 +112,7 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
// 将墨迹添加到 inkCanvas 的父容器中,而不是 inkCanvas.Children
|
||||
// 这样可以避免坐标系统问题
|
||||
var parent = _mainWindow.inkCanvas.Parent as Panel;
|
||||
if (parent != null)
|
||||
if (_mainWindow.inkCanvas.Parent is Panel parent)
|
||||
{
|
||||
parent.Children.Add(strokeVisual);
|
||||
}
|
||||
@@ -159,8 +158,7 @@ namespace Ink_Canvas.Helpers
|
||||
try
|
||||
{
|
||||
// 从父容器中移除墨迹
|
||||
var parent = _mainWindow.inkCanvas?.Parent as Panel;
|
||||
if (parent != null && parent.Children.Contains(visual))
|
||||
if (_mainWindow.inkCanvas?.Parent is Panel parent && parent.Children.Contains(visual))
|
||||
{
|
||||
parent.Children.Remove(visual);
|
||||
}
|
||||
@@ -518,8 +516,7 @@ namespace Ink_Canvas.Helpers
|
||||
originalVisual.Visibility = Visibility.Hidden;
|
||||
|
||||
var segments = new List<UIElement>();
|
||||
var parent = _mainWindow.inkCanvas?.Parent as Panel;
|
||||
if (parent == null)
|
||||
if (!(_mainWindow.inkCanvas?.Parent is Panel parent))
|
||||
{
|
||||
// 如果父容器不是Panel,直接使用InkCanvas
|
||||
parent = null; // 稍后会检查并使用InkCanvas.Children
|
||||
@@ -875,8 +872,7 @@ namespace Ink_Canvas.Helpers
|
||||
try
|
||||
{
|
||||
// 从父容器中移除墨迹
|
||||
var parent = _mainWindow.inkCanvas?.Parent as Panel;
|
||||
if (parent != null && parent.Children.Contains(visual))
|
||||
if (_mainWindow.inkCanvas?.Parent is Panel parent && parent.Children.Contains(visual))
|
||||
{
|
||||
parent.Children.Remove(visual);
|
||||
}
|
||||
|
||||
@@ -313,8 +313,7 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn
|
||||
var buttonElement = _launcherButton.Element;
|
||||
|
||||
// 查找浮动栏
|
||||
var floatingBar = mainWindow.FindName("StackPanelFloatingBar") as Panel;
|
||||
if (floatingBar == null)
|
||||
if (!(mainWindow.FindName("StackPanelFloatingBar") is Panel floatingBar))
|
||||
{
|
||||
// 如果直接查找失败,则尝试遍历可视树查找
|
||||
Panel floatingBarPanelFromTree = null;
|
||||
@@ -405,8 +404,7 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn
|
||||
var buttonElement = _launcherButton.Element;
|
||||
|
||||
// 查找浮动栏
|
||||
var floatingBar = mainWindow.FindName("StackPanelFloatingBar") as Panel;
|
||||
if (floatingBar == null)
|
||||
if (!(mainWindow.FindName("StackPanelFloatingBar") is Panel floatingBar))
|
||||
{
|
||||
// 如果直接查找失败,则尝试遍历可视树查找
|
||||
Panel floatingBarPanelFromTree = null;
|
||||
|
||||
@@ -25,8 +25,7 @@ namespace Ink_Canvas.Helpers
|
||||
return Screen.PrimaryScreen;
|
||||
|
||||
// 获取窗口的句柄
|
||||
var hwndSource = PresentationSource.FromVisual(window) as HwndSource;
|
||||
if (hwndSource == null)
|
||||
if (!(PresentationSource.FromVisual(window) is HwndSource hwndSource))
|
||||
return Screen.PrimaryScreen;
|
||||
|
||||
// 获取窗口在屏幕上的位置
|
||||
|
||||
@@ -61,8 +61,7 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
if (windowTitle.Length == windowName.Length)
|
||||
{
|
||||
WindowPattern windowPattern = window.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
|
||||
if (windowPattern != null)
|
||||
if (window.GetCurrentPattern(WindowPattern.Pattern) is WindowPattern windowPattern)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -70,8 +69,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowPattern windowPattern = window.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
|
||||
if (windowPattern != null)
|
||||
if (window.GetCurrentPattern(WindowPattern.Pattern) is WindowPattern windowPattern)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ using System.Windows.Threading;
|
||||
using Application = System.Windows.Application;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
using Button = System.Windows.Controls.Button;
|
||||
using ComboBox = System.Windows.Controls.ComboBox;
|
||||
using Cursor = System.Windows.Input.Cursor;
|
||||
using Cursors = System.Windows.Input.Cursors;
|
||||
using DpiChangedEventArgs = System.Windows.DpiChangedEventArgs;
|
||||
@@ -328,8 +329,7 @@ namespace Ink_Canvas
|
||||
|
||||
private void inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var inkCanvas1 = sender as InkCanvas;
|
||||
if (inkCanvas1 == null) return;
|
||||
if (!(sender is InkCanvas inkCanvas1)) return;
|
||||
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas1);
|
||||
@@ -358,8 +358,7 @@ namespace Ink_Canvas
|
||||
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink) forcePointEraser = !forcePointEraser;
|
||||
|
||||
// 处理橡皮擦覆盖层的启用/禁用
|
||||
var eraserOverlay = FindName("EraserOverlayCanvas") as Canvas;
|
||||
if (eraserOverlay != null)
|
||||
if (FindName("EraserOverlayCanvas") is Canvas eraserOverlay)
|
||||
{
|
||||
if (inkCanvas1.EditingMode == InkCanvasEditingMode.EraseByPoint)
|
||||
{
|
||||
@@ -1301,8 +1300,7 @@ namespace Ink_Canvas
|
||||
BorderSettingsMask.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
|
||||
|
||||
// 获取SettingsPanelScrollViewer中的所有GroupBox
|
||||
var stackPanel = SettingsPanelScrollViewer.Content as StackPanel;
|
||||
if (stackPanel == null) return;
|
||||
if (!(SettingsPanelScrollViewer.Content is StackPanel stackPanel)) return;
|
||||
|
||||
// 确保所有GroupBox都是可见的
|
||||
foreach (var child in stackPanel.Children)
|
||||
@@ -1517,20 +1515,15 @@ namespace Ink_Canvas
|
||||
// 清除所有导航按钮的Tag属性
|
||||
private void ClearAllNavButtonTags()
|
||||
{
|
||||
var grid = BorderSettings.Child as Grid;
|
||||
if (grid == null) return;
|
||||
if (!(BorderSettings.Child is Grid grid)) return;
|
||||
|
||||
var navSidebar = grid.Children[0] as Border;
|
||||
if (navSidebar == null) return;
|
||||
if (!(grid.Children[0] is Border navSidebar)) return;
|
||||
|
||||
var navGrid = navSidebar.Child as Grid;
|
||||
if (navGrid == null) return;
|
||||
if (!(navSidebar.Child is Grid navGrid)) return;
|
||||
|
||||
var scrollViewer = navGrid.Children[1] as ScrollViewer;
|
||||
if (scrollViewer == null) return;
|
||||
if (!(navGrid.Children[1] is ScrollViewer scrollViewer)) return;
|
||||
|
||||
var stackPanel = scrollViewer.Content as StackPanel;
|
||||
if (stackPanel == null) return;
|
||||
if (!(scrollViewer.Content is StackPanel stackPanel)) return;
|
||||
|
||||
foreach (var child in stackPanel.Children)
|
||||
{
|
||||
@@ -1544,30 +1537,24 @@ namespace Ink_Canvas
|
||||
// 设置导航按钮的Tag属性
|
||||
private void SetNavButtonTag(string tag)
|
||||
{
|
||||
var grid = BorderSettings.Child as Grid;
|
||||
if (grid == null) return;
|
||||
if (!(BorderSettings.Child is Grid grid)) return;
|
||||
|
||||
var navSidebar = grid.Children[0] as Border;
|
||||
if (navSidebar == null) return;
|
||||
if (!(grid.Children[0] is Border navSidebar)) return;
|
||||
|
||||
var navGrid = navSidebar.Child as Grid;
|
||||
if (navGrid == null) return;
|
||||
if (!(navSidebar.Child is Grid navGrid)) return;
|
||||
|
||||
var scrollViewer = navGrid.Children[1] as ScrollViewer;
|
||||
if (scrollViewer == null) return;
|
||||
if (!(navGrid.Children[1] is ScrollViewer scrollViewer)) return;
|
||||
|
||||
var stackPanel = scrollViewer.Content as StackPanel;
|
||||
if (stackPanel == null) return;
|
||||
if (!(scrollViewer.Content is StackPanel stackPanel)) return;
|
||||
|
||||
foreach (var child in stackPanel.Children)
|
||||
{
|
||||
if (child is Button button)
|
||||
{
|
||||
// 检查按钮的ToolTip属性,根据tag设置对应的按钮
|
||||
string buttonTag = button.Tag as string;
|
||||
|
||||
// 如果按钮的Tag与要设置的tag匹配,则设置Tag
|
||||
if (buttonTag != null && buttonTag.ToLower() == tag.ToLower())
|
||||
if (button.Tag is string buttonTag && buttonTag.ToLower() == tag.ToLower())
|
||||
{
|
||||
button.Tag = tag;
|
||||
return;
|
||||
@@ -2546,8 +2533,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
// 获取滑块的轨道元素
|
||||
var track = slider.Template.FindName("PART_Track", slider) as Track;
|
||||
if (track == null)
|
||||
if (!(slider.Template.FindName("PART_Track", slider) is Track track))
|
||||
{
|
||||
// 如果找不到轨道,使用简单方法
|
||||
UpdateSliderValueFromPosition(slider, position);
|
||||
@@ -2674,8 +2660,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
try
|
||||
{
|
||||
var toggle = sender as ToggleSwitch;
|
||||
if (toggle != null)
|
||||
if (sender is ToggleSwitch toggle)
|
||||
{
|
||||
Settings.ModeSettings.IsPPTOnlyMode = toggle.IsOn;
|
||||
|
||||
@@ -2773,8 +2758,7 @@ namespace Ink_Canvas
|
||||
|
||||
try
|
||||
{
|
||||
System.Windows.Controls.ComboBox comboBox = sender as System.Windows.Controls.ComboBox;
|
||||
if (comboBox != null)
|
||||
if (sender is ComboBox comboBox)
|
||||
{
|
||||
Settings.Appearance.Theme = comboBox.SelectedIndex;
|
||||
|
||||
|
||||
@@ -238,9 +238,8 @@ namespace Ink_Canvas
|
||||
RefreshBlackBoardSidePageListView();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardBorderLeftPageListView);
|
||||
await Task.Delay(1);
|
||||
var leftContainer = BlackBoardLeftSidePageListView.ItemContainerGenerator.ContainerFromIndex(
|
||||
CurrentWhiteboardIndex - 1) as ListViewItem;
|
||||
if (leftContainer != null)
|
||||
if (BlackBoardLeftSidePageListView.ItemContainerGenerator.ContainerFromIndex(
|
||||
CurrentWhiteboardIndex - 1) is ListViewItem leftContainer)
|
||||
{
|
||||
ScrollViewToVerticalTop(leftContainer, BlackBoardLeftSidePageListScrollViewer);
|
||||
}
|
||||
@@ -258,9 +257,8 @@ namespace Ink_Canvas
|
||||
RefreshBlackBoardSidePageListView();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardBorderRightPageListView);
|
||||
await Task.Delay(1);
|
||||
var rightContainer = BlackBoardRightSidePageListView.ItemContainerGenerator.ContainerFromIndex(
|
||||
CurrentWhiteboardIndex - 1) as ListViewItem;
|
||||
if (rightContainer != null)
|
||||
if (BlackBoardRightSidePageListView.ItemContainerGenerator.ContainerFromIndex(
|
||||
CurrentWhiteboardIndex - 1) is ListViewItem rightContainer)
|
||||
{
|
||||
ScrollViewToVerticalTop(rightContainer, BlackBoardRightSidePageListScrollViewer);
|
||||
}
|
||||
|
||||
@@ -504,8 +504,7 @@ namespace Ink_Canvas
|
||||
BackgroundPalette.Child = stackPanel;
|
||||
|
||||
// 获取主窗口中的根网格,确保面板添加到顶层
|
||||
Grid mainGrid = FindName("Main_Grid") as Grid;
|
||||
if (mainGrid != null)
|
||||
if (FindName("Main_Grid") is Grid mainGrid)
|
||||
{
|
||||
// 删除可能已存在的BackgroundPalette
|
||||
foreach (UIElement element in mainGrid.Children)
|
||||
@@ -526,8 +525,7 @@ namespace Ink_Canvas
|
||||
mainGrid.Children.Add(BackgroundPalette);
|
||||
|
||||
// 设置面板位置
|
||||
var clickElement = FindName("BoardChangeBackgroundColorBtn") as FrameworkElement;
|
||||
if (clickElement != null)
|
||||
if (FindName("BoardChangeBackgroundColorBtn") is FrameworkElement clickElement)
|
||||
{
|
||||
Point position = clickElement.TranslatePoint(new Point(0, 0), mainGrid);
|
||||
BackgroundPalette.Margin = new Thickness(
|
||||
@@ -551,10 +549,9 @@ namespace Ink_Canvas
|
||||
{
|
||||
if (modePanel.Children.Count > 1)
|
||||
{
|
||||
var whiteboardButton = modePanel.Children[0] as Border;
|
||||
var blackboardButton = modePanel.Children[1] as Border;
|
||||
|
||||
if (whiteboardButton != null && whiteboardButton.Child is TextBlock whiteboardText)
|
||||
if (modePanel.Children[0] is Border whiteboardButton && whiteboardButton.Child is TextBlock whiteboardText)
|
||||
{
|
||||
whiteboardButton.Background = Settings.Canvas.UsingWhiteboard ?
|
||||
new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)) :
|
||||
|
||||
@@ -85,9 +85,8 @@ namespace Ink_Canvas
|
||||
|
||||
// 根据橡皮擦形状选择对应的图像资源
|
||||
string resourceKey = isEraserCircleShape ? "EllipseEraserImageSource" : "RectangleEraserImageSource";
|
||||
var imageSource = TryFindResource(resourceKey) as DrawingImage;
|
||||
|
||||
if (imageSource != null)
|
||||
|
||||
if (TryFindResource(resourceKey) is DrawingImage imageSource)
|
||||
{
|
||||
eraserFeedback.Source = imageSource;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ namespace Ink_Canvas
|
||||
foreach (var kvp in Settings.Automation.FloatingWindowInterceptor.InterceptRules)
|
||||
{
|
||||
var toggleName = $"ToggleSwitch{kvp.Key}";
|
||||
var toggle = FindName(toggleName) as ToggleSwitch;
|
||||
if (toggle != null)
|
||||
if (FindName(toggleName) is ToggleSwitch toggle)
|
||||
{
|
||||
toggle.IsOn = kvp.Value;
|
||||
}
|
||||
|
||||
@@ -2895,8 +2895,7 @@ namespace Ink_Canvas
|
||||
private async void UpdateChannelSelector_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
var radioButton = sender as RadioButton;
|
||||
if (radioButton != null)
|
||||
if (sender is RadioButton radioButton)
|
||||
{
|
||||
string channel = radioButton.Tag.ToString();
|
||||
UpdateChannel newChannel = channel == "Beta" ? UpdateChannel.Beta : UpdateChannel.Release;
|
||||
|
||||
@@ -489,20 +489,16 @@ namespace Ink_Canvas
|
||||
{
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
|
||||
// 修复:几何绘制模式下完全禁止触摸轨迹收集
|
||||
|
||||
if (drawingShapeMode != 0)
|
||||
{
|
||||
// 确保几何绘制模式下不切换到Ink模式,避免触摸轨迹被收集
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
|
||||
if (isWaitUntilNextTouchDown && dec.Count > 1) return;
|
||||
if (dec.Count > 1)
|
||||
{
|
||||
// 修复:双曲线绘制时,多指触摸不应该删除第一笔的辅助线
|
||||
if ((drawingShapeMode == 24 || drawingShapeMode == 25) && drawMultiStepShapeCurrentStep == 1)
|
||||
{
|
||||
// 第二笔绘制双曲线时,只删除第二笔的临时笔画,保留第一笔的辅助线
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
@@ -523,13 +519,10 @@ namespace Ink_Canvas
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 修复:双曲线绘制时,第二笔应该基于第一笔的起点,而不是触摸实时位置
|
||||
|
||||
Point touchPoint = e.GetTouchPoint(inkCanvas).Position;
|
||||
if ((drawingShapeMode == 24 || drawingShapeMode == 25) && drawMultiStepShapeCurrentStep == 1)
|
||||
{
|
||||
// 第二笔绘制双曲线时,使用触摸位置作为终点,但保持第一笔的起点
|
||||
// 这里不需要特殊处理,因为MouseTouchMove函数内部已经正确处理了双曲线的绘制逻辑
|
||||
MouseTouchMove(touchPoint);
|
||||
}
|
||||
else
|
||||
@@ -538,15 +531,13 @@ namespace Ink_Canvas
|
||||
MouseTouchMove(touchPoint);
|
||||
}
|
||||
|
||||
return; // 处理完几何绘制后直接返回,不执行后面的代码
|
||||
return;
|
||||
}
|
||||
|
||||
// 其它模式下,允许橡皮、套索、批注等正常工作,不覆盖EditingMode
|
||||
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.Select ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.Ink)
|
||||
{
|
||||
// 允许正常橡皮、套索、批注
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,22 +211,18 @@ namespace Ink_Canvas
|
||||
// 获取全局快捷键管理器
|
||||
var hotkeyManagerField = typeof(MainWindow).GetField("_globalHotkeyManager",
|
||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
var hotkeyManager = hotkeyManagerField?.GetValue(mainWin) as GlobalHotkeyManager;
|
||||
|
||||
if (hotkeyManager != null)
|
||||
|
||||
if (hotkeyManagerField?.GetValue(mainWin) is GlobalHotkeyManager hotkeyManager)
|
||||
{
|
||||
// 禁用所有快捷键
|
||||
hotkeyManager.DisableHotkeyRegistration();
|
||||
|
||||
// 更新菜单项文本和状态
|
||||
var menuItem = sender as MenuItem;
|
||||
if (menuItem != null)
|
||||
if (sender is MenuItem menuItem)
|
||||
{
|
||||
var headerPanel = menuItem.Header as SimpleStackPanel;
|
||||
if (headerPanel != null)
|
||||
if (menuItem.Header is SimpleStackPanel headerPanel)
|
||||
{
|
||||
var textBlock = headerPanel.Children[0] as TextBlock;
|
||||
if (textBlock != null)
|
||||
if (headerPanel.Children[0] is TextBlock textBlock)
|
||||
{
|
||||
if (textBlock.Text == "禁用所有快捷键")
|
||||
{
|
||||
|
||||
@@ -517,18 +517,17 @@ namespace Ink_Canvas
|
||||
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// 检查是否点击了UI元素,如果是则不处理选择
|
||||
var hitElement = e.Source as FrameworkElement;
|
||||
if (hitElement != null && (
|
||||
hitElement is Ellipse ||
|
||||
hitElement is System.Windows.Controls.Button ||
|
||||
hitElement is Border ||
|
||||
hitElement is TextBlock ||
|
||||
hitElement is StackPanel ||
|
||||
hitElement is Separator ||
|
||||
hitElement.Name == "SizeInfoBorder" ||
|
||||
hitElement.Name == "HintText" ||
|
||||
hitElement.Name == "AdjustModeHint" ||
|
||||
hitElement.Name == "SelectionRectangle"))
|
||||
if (e.Source is FrameworkElement hitElement && (
|
||||
hitElement is Ellipse ||
|
||||
hitElement is System.Windows.Controls.Button ||
|
||||
hitElement is Border ||
|
||||
hitElement is TextBlock ||
|
||||
hitElement is StackPanel ||
|
||||
hitElement is Separator ||
|
||||
hitElement.Name == "SizeInfoBorder" ||
|
||||
hitElement.Name == "HintText" ||
|
||||
hitElement.Name == "AdjustModeHint" ||
|
||||
hitElement.Name == "SelectionRectangle"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -440,16 +440,14 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
private void ToggleSwitch_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var border = sender as Border;
|
||||
if (border != null)
|
||||
if (sender is Border border)
|
||||
{
|
||||
// 切换开关状态
|
||||
bool isOn = border.Background.ToString() == "#FF3584E4";
|
||||
border.Background = isOn ? new SolidColorBrush(Color.FromRgb(225, 225, 225)) : new SolidColorBrush(Color.FromRgb(53, 132, 228));
|
||||
|
||||
// 切换内部圆点的位置
|
||||
var innerBorder = border.Child as Border;
|
||||
if (innerBorder != null)
|
||||
if (border.Child is Border innerBorder)
|
||||
{
|
||||
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Left : HorizontalAlignment.Right;
|
||||
}
|
||||
@@ -557,8 +555,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
private void OptionButton_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var border = sender as Border;
|
||||
if (border != null)
|
||||
if (sender is Border border)
|
||||
{
|
||||
string tag = border.Tag?.ToString();
|
||||
if (!string.IsNullOrEmpty(tag))
|
||||
@@ -568,8 +565,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
// 设置当前按钮为选中状态
|
||||
border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
|
||||
var textBlock = border.Child as TextBlock;
|
||||
if (textBlock != null)
|
||||
if (border.Child is TextBlock textBlock)
|
||||
{
|
||||
textBlock.FontWeight = FontWeights.Bold;
|
||||
}
|
||||
@@ -583,8 +579,7 @@ namespace Ink_Canvas.Windows
|
||||
private void ClearOtherOptionsInGroup(Border currentBorder, string currentTag)
|
||||
{
|
||||
// 获取当前按钮所在的父容器
|
||||
var parent = currentBorder.Parent as StackPanel;
|
||||
if (parent != null)
|
||||
if (currentBorder.Parent is StackPanel parent)
|
||||
{
|
||||
// 获取组名(Tag中下划线前的部分)
|
||||
string groupName = currentTag.Split('_')[0];
|
||||
@@ -598,8 +593,7 @@ namespace Ink_Canvas.Windows
|
||||
if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(groupName + "_"))
|
||||
{
|
||||
border.Background = new SolidColorBrush(Colors.Transparent);
|
||||
var textBlock = border.Child as TextBlock;
|
||||
if (textBlock != null)
|
||||
if (border.Child is TextBlock textBlock)
|
||||
{
|
||||
textBlock.FontWeight = FontWeights.Normal;
|
||||
}
|
||||
@@ -776,8 +770,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
if (child is Border border && border.Background != null)
|
||||
{
|
||||
var brush = border.Background as SolidColorBrush;
|
||||
if (brush != null && brush.Color.ToString() == "#FFDEDEDE")
|
||||
if (border.Background is SolidColorBrush brush && brush.Color.ToString() == "#FFDEDEDE")
|
||||
{
|
||||
return border;
|
||||
}
|
||||
@@ -800,8 +793,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
if (child is Border border && border.Background != null)
|
||||
{
|
||||
var brush = border.Background as SolidColorBrush;
|
||||
if (brush != null && brush.Color.ToString() == "#FF3584E4")
|
||||
if (border.Background is SolidColorBrush brush && brush.Color.ToString() == "#FF3584E4")
|
||||
{
|
||||
return border;
|
||||
}
|
||||
@@ -959,8 +951,7 @@ namespace Ink_Canvas.Windows
|
||||
var relativePosition = Math.Max(0, Math.Min(1, adjustedX / effectiveWidth));
|
||||
|
||||
// 更新滑块位置
|
||||
var thumbTransform = customSlider.ThumbImage.RenderTransform as TranslateTransform;
|
||||
if (thumbTransform == null)
|
||||
if (!(customSlider.ThumbImage.RenderTransform is TranslateTransform thumbTransform))
|
||||
{
|
||||
thumbTransform = new TranslateTransform();
|
||||
customSlider.ThumbImage.RenderTransform = thumbTransform;
|
||||
|
||||
Reference in New Issue
Block a user