Skip to content

Commit

Permalink
fix: close #1457
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Sep 24, 2023
1 parent 5b0be3b commit ef5ab72
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Shared/HandyControl_Shared/Controls/TabControl/TabItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef5ab72

Please sign in to comment.