添加项目文件。

This commit is contained in:
czj
2026-06-05 10:57:09 +08:00
parent f29671b374
commit d960cb5912
166 changed files with 15996 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
using Microsoft.Xaml.Behaviors;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace UIShare.Behaviors
{
//给Border添加双击事件
public class MouseDoubleClickBehavior : Behavior<Border>
{
public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register("Command", typeof(ICommand), typeof(MouseDoubleClickBehavior), new PropertyMetadata(null));
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.Register("CommandParameter", typeof(object), typeof(MouseDoubleClickBehavior), new PropertyMetadata(null));
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
protected override void OnAttached()
{
base.OnAttached();
// 确保 Border 的 Background 不为 null否则无法触发点击事件
this.AssociatedObject.MouseLeftButtonDown += OnMouseLeftButtonDown;
}
protected override void OnDetaching()
{
base.OnDetaching();
this.AssociatedObject.MouseLeftButtonDown -= OnMouseLeftButtonDown;
}
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 判断点击次数是否为 2
if (e.ClickCount == 2)
{
if (Command != null && Command.CanExecute(CommandParameter))
{
Command.Execute(CommandParameter);
}
}
}
}
}

View File

@@ -0,0 +1,59 @@
using Microsoft.Xaml.Behaviors;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace UIShare.Behaviors
{
public class TabControlSelectionChangedBehavior : Behavior<TabControl>
{
public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register(
"Command", typeof(ICommand), typeof(TabControlSelectionChangedBehavior), new PropertyMetadata(null));
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.Register(
"CommandParameter", typeof(object), typeof(TabControlSelectionChangedBehavior), new PropertyMetadata(null));
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public object CommandParameter
{
get { return GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
}
protected override void OnAttached()
{
base.OnAttached();
if (AssociatedObject != null)
{
AssociatedObject.SelectionChanged += OnSelectionChanged;
}
}
protected override void OnDetaching()
{
if (AssociatedObject != null)
{
AssociatedObject.SelectionChanged -= OnSelectionChanged;
}
base.OnDetaching();
}
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var tabItem = AssociatedObject.SelectedItem as TabItem;
// 获取选中 TabItem 的 Header
if (Command != null && Command.CanExecute(tabItem.Header))
{
// 使用选中 TabItem 的 Header 作为 CommandParameter
Command.Execute(((TabItem)AssociatedObject.SelectedItem)?.Header);
}
}
}
}