diff --git a/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs b/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs index d202527c..1b495414 100644 --- a/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs +++ b/src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs @@ -257,7 +257,11 @@ protected override void OnMouseRightButtonDown(MouseButtonEventArgs e) { base.OnMouseRightButtonDown(e); - if (VisualTreeHelper.HitTest(this, e.GetPosition(this)) == null) return; + if (!IsMouseOverHeader(e)) + { + return; + } + IsSelected = true; Focus(); } @@ -300,7 +304,11 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); - if (VisualTreeHelper.HitTest(this, e.GetPosition(this)) == null) return; + if (!IsMouseOverHeader(e)) + { + return; + } + var parent = TabControlParent; if (parent == null) return; @@ -391,7 +399,8 @@ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) protected override void OnMouseDown(MouseButtonEventArgs e) { if (e is { ChangedButton: MouseButton.Middle, ButtonState: MouseButtonState.Pressed } && - TabControlParent.CanBeClosedByMiddleButton) + TabControlParent.CanBeClosedByMiddleButton && + IsMouseOverHeader(e)) { if (ShowCloseButton || ShowContextMenu) { @@ -474,6 +483,11 @@ private int CalLocationIndex(double left) return result > maxIndex ? maxIndex : result; } + private bool IsMouseOverHeader(MouseButtonEventArgs e) + { + return VisualTreeHelper.HitTest(this, e.GetPosition(this)) is not null; + } + public static readonly RoutedEvent ClosingEvent = EventManager.RegisterRoutedEvent("Closing", RoutingStrategy.Bubble, typeof(EventHandler), typeof(TabItem)); public event EventHandler Closing