diff --git a/src/MahApps.Metro/Controls/MetroWindow.cs b/src/MahApps.Metro/Controls/MetroWindow.cs
index 590d153d2..a683aa804 100644
--- a/src/MahApps.Metro/Controls/MetroWindow.cs
+++ b/src/MahApps.Metro/Controls/MetroWindow.cs
@@ -159,6 +159,22 @@ public MultiFrameImageMode IconScalingMode
set => this.SetValue(IconScalingModeProperty, value);
}
+ /// Identifies the dependency property.
+ public static readonly DependencyProperty CloseOnIconDoubleClickProperty
+ = DependencyProperty.Register(nameof(CloseOnIconDoubleClick),
+ typeof(bool),
+ typeof(MetroWindow),
+ new PropertyMetadata(BooleanBoxes.TrueBox));
+
+ ///
+ /// Gets or sets the value to close the window if the user double click on the window icon.
+ ///
+ public bool CloseOnIconDoubleClick
+ {
+ get => (bool)this.GetValue(CloseOnIconDoubleClickProperty);
+ set => this.SetValue(CloseOnIconDoubleClickProperty, BooleanBoxes.Box(value));
+ }
+
/// Identifies the dependency property.
public static readonly DependencyProperty ShowTitleBarProperty
= DependencyProperty.Register(nameof(ShowTitleBar),
@@ -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;
@@ -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)
@@ -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
- }
}
}