优化更新代码,添加界面功能并整合

This commit is contained in:
GG Z
2025-02-10 20:53:40 +08:00
parent 83b846f15f
commit 978e03a67f
1389 changed files with 95739 additions and 22200 deletions

View File

@@ -0,0 +1,76 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace WPFluent.Controls.Primitives;
public class MenuItemGroup : List<MenuItem>
{
public bool IsCanCancel { get; set; } = false;
public static MenuItemGroup GetGroup(DependencyObject obj)
{
return (MenuItemGroup)obj.GetValue(GroupProperty);
}
public static void SetGroup(DependencyObject obj, MenuItemGroup value)
{
obj.SetValue(GroupProperty, value);
}
public static readonly DependencyProperty GroupProperty =
DependencyProperty.RegisterAttached("Group", typeof(MenuItemGroup), typeof(MenuItemGroup), new PropertyMetadata(null!, OnGroupChanged));
private static void OnGroupChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is MenuItem tb)
{
((MenuItemGroup)e.NewValue).Join(tb);
}
}
protected bool Handling { get; set; } = false;
public MenuItemGroup JoinWith(MenuItem menuItem)
{
Join(menuItem);
return this;
}
public void Join(MenuItem menuItem)
{
Add(menuItem);
menuItem.Checked += (s, e) =>
{
if (s is MenuItem mi && GetGroup(mi) is MenuItemGroup group)
{
Handling = true;
foreach (var tb in group)
{
if (tb != mi)
{
tb.IsChecked = false;
}
}
Handling = false;
}
};
menuItem.Unchecked += (s, e) =>
{
if (!IsCanCancel && !Handling && s is MenuItem mi)
{
mi.IsChecked = true;
}
};
SetGroup(menuItem, this);
}
public void Unjoin(MenuItem checkBox)
{
Remove(checkBox);
SetGroup(checkBox, null!);
}
public static MenuItemGroup New() => [];
}