add IgnoreAltF4 Attached Property
This commit is contained in:
1 parent
0f2cb24a3b
commit
9856ff1225
3 files changed
+34
-2
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user