add IgnoreAltF4 Attached Property

This commit is contained in:
NaBian committed 2019-08-07 23:06:33 +08:00
1 parent 0f2cb24a3b
commit 9856ff1225
3 files changed
+34 -2

No files matched your search

@@ -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">
@@ -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);
}
}
@@ -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;