enhance: close #1205
This commit is contained in:
1 parent
8b52df3a06
commit
c544b0796e
2 files changed
+16
-5
No files matched your search
@@ -119,6 +119,15 @@ public class TabControl : System.Windows.Controls.TabControl
|
||||
set => SetValue(ShowContextMenuProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CanBeClosedByMiddleButtonProperty =
|
||||
DependencyProperty.Register("CanBeClosedByMiddleButton", typeof(bool), typeof(TabControl), new PropertyMetadata(ValueBoxes.TrueBox));
|
||||
|
||||
public bool CanBeClosedByMiddleButton
|
||||
{
|
||||
get => (bool) GetValue(CanBeClosedByMiddleButtonProperty);
|
||||
set => SetValue(CanBeClosedByMiddleButtonProperty, ValueBoxes.BooleanBox(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否将标签填充
|
||||
/// </summary>
|
||||
|
||||
@@ -242,10 +242,11 @@ public class TabItem : System.Windows.Controls.TabItem
|
||||
public TabItem()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => Close()));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.CloseAll,
|
||||
(s, e) => { TabControlParent.CloseAllItems(); }));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.CloseOther,
|
||||
(s, e) => { TabControlParent.CloseOtherItems(this); }));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.CloseAll, (s, e) => TabControlParent.CloseAllItems()));
|
||||
CommandBindings.Add(new CommandBinding(
|
||||
ControlCommands.CloseOther,
|
||||
(s, e) => TabControlParent.CloseOtherItems(this),
|
||||
(s, e) => e.CanExecute = TabControlParent.Items.Count > 1));
|
||||
|
||||
Loaded += (s, e) => OnMenuChanged(Menu);
|
||||
}
|
||||
@@ -389,7 +390,8 @@ public class TabItem : System.Windows.Controls.TabItem
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
|
||||
if (e is { ChangedButton: MouseButton.Middle, ButtonState: MouseButtonState.Pressed } &&
|
||||
TabControlParent.CanBeClosedByMiddleButton)
|
||||
{
|
||||
if (ShowCloseButton || ShowContextMenu)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user