忽略WPF应用程序中的Alt + F4

时间:2010-08-31 15:58:33

标签: c# wpf

如何在WPF应用程序中忽略 Alt + F4

3 个答案:

答案 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

C#

void Form1_Cancel( Object^ /*sender*/, CancelEventArgs^ e )
{
   e->Cancel = true;
}

C ++

Private Sub Form1_Closing(sender As Object, e As _
   System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    e.Cancel = True
End Sub 'Form1_Closing

VB.NET

{{1}}

答案 2 :(得分:7)

只需在View(Xaml)文件中使用这样的输入绑定:

<Window.InputBindings>
    <KeyBinding Modifiers="Alt" Key="F4" Command="{Binding Path=ToDelegateCommandThatExecuteNothing}" />
</Window.InputBindings>