diff --git a/src/Shared/HandyControlDemo_Shared/MainWindow.xaml b/src/Shared/HandyControlDemo_Shared/MainWindow.xaml index e82bc22b..9ff31060 100644 --- a/src/Shared/HandyControlDemo_Shared/MainWindow.xaml +++ b/src/Shared/HandyControlDemo_Shared/MainWindow.xaml @@ -12,9 +12,10 @@ ShowTitle="False" ResizeMode="CanResizeWithGrip" WindowStartupLocation="CenterScreen" - hc:GlobalShortcut.Host="True" DataContext="{Binding Main,Source={StaticResource Locator}}" + hc:GlobalShortcut.Host="True" hc:Dialog.Token="{x:Static data:MessageToken.MainWindow}" + hc:WindowAttach.IgnoreAltF4="True" d:DesignHeight="800" d:DesignWidth="1400" Icon="/HandyControlDemo;component/Resources/Img/icon.ico"> diff --git a/src/Shared/HandyControl_Shared/Controls/Attach/WindowAttach.cs b/src/Shared/HandyControl_Shared/Controls/Attach/WindowAttach.cs index 99909ec9..fb600659 100644 --- a/src/Shared/HandyControl_Shared/Controls/Attach/WindowAttach.cs +++ b/src/Shared/HandyControl_Shared/Controls/Attach/WindowAttach.cs @@ -37,5 +37,37 @@ namespace HandyControl.Controls System.Windows.Window.GetWindow(obj)?.DragMove(); } } + + public static readonly DependencyProperty IgnoreAltF4Property = DependencyProperty.RegisterAttached( + "IgnoreAltF4", typeof(bool), typeof(WindowAttach), new PropertyMetadata(ValueBoxes.FalseBox, OnIgnoreAltF4Changed)); + + private static void OnIgnoreAltF4Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is System.Windows.Window window) + { + if ((bool)e.NewValue) + { + window.PreviewKeyDown += Window_PreviewKeyDown; + } + else + { + window.PreviewKeyDown -= Window_PreviewKeyDown; + } + } + } + + private static void Window_PreviewKeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.System && e.SystemKey == Key.F4) + { + e.Handled = true; + } + } + + public static void SetIgnoreAltF4(DependencyObject element, bool value) + => element.SetValue(IgnoreAltF4Property, value); + + public static bool GetIgnoreAltF4(DependencyObject element) + => (bool) element.GetValue(IgnoreAltF4Property); } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index f4b8aa78..761fa2d9 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -1,7 +1,6 @@ using System; using System.Windows; using System.Windows.Controls; -using System.Windows.Documents; using System.Windows.Input; using HandyControl.Data; using HandyControl.Interactivity;