From e395b8d2cdf5d18f77da14c2a3d1b6b036a245c0 Mon Sep 17 00:00:00 2001 From: punker76 Date: Tue, 9 Apr 2019 22:25:53 +0200 Subject: [PATCH] (GH-3453) Fix for: How to disable System Menu On Left Click at the Icon of a MetroWindow Add new property ShowSystemMenu: Gets or sets a value that indicates whether the system menu should popup with left mouse click on the window icon. --- .../MahApps.Metro.Demo/MainWindow.xaml | 7 +++++++ src/MahApps.Metro/Controls/MetroWindow.cs | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml index 3e0d472798..85ce7042c9 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml @@ -227,6 +227,13 @@ Header="Window icon: no scale, smaller frame" IsCheckable="True" IsChecked="{Binding IsNoScaleSmallerFrame, Mode=OneWay}" /> + + + diff --git a/src/MahApps.Metro/Controls/MetroWindow.cs b/src/MahApps.Metro/Controls/MetroWindow.cs index 643f780f20..7420e087cd 100644 --- a/src/MahApps.Metro/Controls/MetroWindow.cs +++ b/src/MahApps.Metro/Controls/MetroWindow.cs @@ -84,6 +84,7 @@ public class MetroWindow : Window /// public static readonly DependencyProperty IsCloseButtonEnabledWithDialogProperty = IsCloseButtonEnabledWithDialogPropertyKey.DependencyProperty; + public static readonly DependencyProperty ShowSystemMenuProperty = DependencyProperty.Register("ShowSystemMenu", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); public static readonly DependencyProperty ShowSystemMenuOnRightClickProperty = DependencyProperty.Register("ShowSystemMenuOnRightClick", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); public static readonly DependencyProperty TitleBarHeightProperty = DependencyProperty.Register("TitleBarHeight", typeof(int), typeof(MetroWindow), new PropertyMetadata(30, TitleBarHeightPropertyChangedCallback)); @@ -549,7 +550,16 @@ public bool IsCloseButtonEnabledWithDialog } /// - /// Gets/sets if the the system menu should popup on right click. + /// Gets or sets a value that indicates whether the system menu should popup with left mouse click on the window icon. + /// + public bool ShowSystemMenu + { + get { return (bool)GetValue(ShowSystemMenuProperty); } + set { SetValue(ShowSystemMenuProperty, value); } + } + + /// + /// Gets or sets a value that indicates whether the system menu should popup with right mouse click if the mouse position is on title bar or on the entire window if it has no title bar (and no title bar height). /// public bool ShowSystemMenuOnRightClick { @@ -1307,7 +1317,7 @@ private void IconMouseDown(object sender, MouseButtonEventArgs e) { Close(); } - else + else if (this.ShowSystemMenu) { ShowSystemMenuPhysicalCoordinates(this, PointToScreen(new Point(0, TitleBarHeight))); }