feat: 提取勾选框左右键点击单次执行逻辑

This commit is contained in:
uye
2023-12-12 18:04:01 +08:00
parent c92d4a6db6
commit 0f8cbf0f1a
2 changed files with 42 additions and 10 deletions

View File

@@ -0,0 +1,39 @@
// <copyright file="CheckBoxHelper.cs" company="MaaAssistantArknights">
// MaaWpfGui - A part of the MaaCoreArknights project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
// </copyright>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace MaaWpfGui.Helper
{
public static class CheckBoxHelper
{
public static void ToggleCheckBoxNullOnRightClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Right)
{
return;
}
CheckBox checkBox = (CheckBox)sender;
checkBox.IsChecked = checkBox.IsChecked == null ? (bool?)false : null;
}
public static void ToggleCheckBoxNullOnLeftClick(object sender, RoutedEventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
checkBox.IsChecked = checkBox.IsChecked == true ? null : (bool?)false;
}
}
}

View File

@@ -13,8 +13,8 @@
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using MaaWpfGui.Helper;
namespace MaaWpfGui.Views.UserControl
{
@@ -42,19 +42,12 @@ namespace MaaWpfGui.Views.UserControl
private void ToggleCheckBoxNullOnRightClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Right)
{
return;
}
CheckBox checkBox = (CheckBox)sender;
checkBox.IsChecked = checkBox.IsChecked == null ? (bool?)false : null;
CheckBoxHelper.ToggleCheckBoxNullOnRightClick(sender, e);
}
private void ToggleCheckBoxNullOnLeftClick(object sender, RoutedEventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
checkBox.IsChecked = checkBox.IsChecked == true ? null : (bool?)false;
CheckBoxHelper.ToggleCheckBoxNullOnLeftClick(sender, e);
}
}
}