如何在WPF应用程序中忽略 Alt + F4 ?
答案 0 :(得分:35)
将此添加到您不希望Alt + F4工作的UIElement/FramworkElement
。
wnd.KeyDown += new KeyEventHandler(wnd_KeyDown);
void wnd_KeyDown(object sender, KeyEventArgs e)
{
if ( e.Key == Key.System && e.SystemKey == Key.F4)
{
e.Handled = true;
}
}
答案 1 :(得分:14)
您可以在OnClosing
上强制TForm
事件,并在cea.Cancel = true;
CancelEventArgs
参数中设置OnClosing
时设置private void Form1_Closing(Object sender, CancelEventArgs e) {
e.Cancel = true;
}
。
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onclosing.aspx
void Form1_Cancel( Object^ /*sender*/, CancelEventArgs^ e )
{
e->Cancel = true;
}
Private Sub Form1_Closing(sender As Object, e As _
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub 'Form1_Closing
{{1}}
答案 2 :(得分:7)
只需在View(Xaml)文件中使用这样的输入绑定:
<Window.InputBindings>
<KeyBinding Modifiers="Alt" Key="F4" Command="{Binding Path=ToDelegateCommandThatExecuteNothing}" />
</Window.InputBindings>