KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The basic idea behind a Cancel button is to enable closing your window with an Escape Keypress. You can set the IsCancel property on the Cancel button to true, causing the Cancel button to automatically close the dialog without handling the Click event. Source: Programming WPF (Griffith, Sells) So this should work <Window> <Button Name="btnCancel" IsCancel="True">_Close</Button> </Window> However the behavior I expect isn't working out for me. The parent window is the main application window specified by the Application.StartupUri property. What works is <Button Name="btnCancel" IsCancel=True" Click="CloseWindow">_Close</Button> private void CloseWindow(object sender, RoutedEventArgs) { this.Close(); } Is the behavior of IsCancel different based on whether the Window is a normal window or a Dialog? Does IsCancel work as advertised only if ShowDialog has been called? Is an explicit Click handler required for the button (with IsCancel set to true) to close a window on an Escape press?
Tags (comma-separated)
Save Edits
Cancel