<Button Content="Close" Click="OnClose" IsCancel="True" />
On a recent project, however, I did not have a close button to set IsCancel on. The solution is to use WPF commands and input gestures. Here is an example:
<Window.CommandBindings> <CommandBinding Command="Close" Executed="OnCloseCmdExecuted" /> </Window.CommandBindings> <Window.InputBindings> <KeyBinding Command="Close" Key="Escape" /> </Window.InputBindings>
private void OnCloseCmdExecuted(object sender, ExecutedRoutedEventArgs e) { this.Close(); }
No comments:
Post a Comment