Skip to content

Commit

Permalink
feat: #4445 add new property CloseOnIconDoubleClick
Browse files Browse the repository at this point in the history
Add new property CloseOnIconDoubleClick to allow disable closing window if the user double clicks on window icon.
  • Loading branch information
punker76 committed Dec 10, 2023
1 parent 6fc16f3 commit 5ea6fd1
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ public MultiFrameImageMode IconScalingMode
set => this.SetValue(IconScalingModeProperty, value);
}

/// <summary>Identifies the <see cref="CloseOnIconDoubleClick"/> dependency property.</summary>
public static readonly DependencyProperty CloseOnIconDoubleClickProperty
= DependencyProperty.Register(nameof(CloseOnIconDoubleClick),
typeof(bool),
typeof(MetroWindow),
new PropertyMetadata(BooleanBoxes.TrueBox));

/// <summary>
/// Gets or sets the value to close the window if the user double click on the window icon.
/// </summary>
public bool CloseOnIconDoubleClick
{
get => (bool)this.GetValue(CloseOnIconDoubleClickProperty);
set => this.SetValue(CloseOnIconDoubleClickProperty, BooleanBoxes.Box(value));
}

/// <summary>Identifies the <see cref="ShowTitleBar"/> dependency property.</summary>
public static readonly DependencyProperty ShowTitleBarProperty
= DependencyProperty.Register(nameof(ShowTitleBar),
Expand Down Expand Up @@ -1479,7 +1495,7 @@ private void ClearWindowEvents()

if (this.icon != null)
{
this.icon.MouseDown -= this.IconMouseDown;
this.icon.MouseLeftButtonDown -= this.OnIconMouseLeftButtonDown;
}

this.SizeChanged -= this.MetroWindow_SizeChanged;
Expand All @@ -1493,7 +1509,7 @@ private void SetWindowEvents()
// set mouse down/up for icon
if (this.icon != null && this.icon.Visibility == Visibility.Visible)
{
this.icon.MouseDown += this.IconMouseDown;
this.icon.MouseDown += this.OnIconMouseLeftButtonDown;
}

if (this.windowTitleThumb != null)
Expand Down Expand Up @@ -1527,20 +1543,17 @@ private void SetWindowEvents()
}
}

private void IconMouseDown(object sender, MouseButtonEventArgs e)
private void OnIconMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
if (e.ClickCount == 2 && this.CloseOnIconDoubleClick)
{
this.Close();
}
else if (this.ShowSystemMenu)
{
if (e.ClickCount == 2)
{
this.Close();
}
else if (this.ShowSystemMenu)
{
#pragma warning disable 618
ControlzEx.SystemCommands.ShowSystemMenuPhysicalCoordinates(this, this.PointToScreen(new Point(this.BorderThickness.Left, this.TitleBarHeight + this.BorderThickness.Top)));
ControlzEx.SystemCommands.ShowSystemMenuPhysicalCoordinates(this, this.PointToScreen(new Point(this.BorderThickness.Left, this.TitleBarHeight + this.BorderThickness.Top)));
#pragma warning restore 618
}
}
}

Expand Down

0 comments on commit 5ea6fd1

Please sign in to comment.