#313 – Specify a Cancel Button in a Window
June 3, 2011 1 Comment
You can use the IsCancel property to specify that a particular button in a window is the cancel button. You can still click on the button like you would any other button in the window, but if you press the ESC (Escape) key, the cancel button will respond as if it was clicked. The button responds to the ESC key, no matter which control currently has keyboard focus.
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <Button Content="Save" Width="100" Margin="10,20,10,20" IsDefault="True" Click="Save_Click"/> <Button Content="Cancel" Width="100" Margin="10,20,10,20" IsCancel="True" Click="Cancel_Click"/> </StackPanel>
Pingback: #314 – Typical Usage for Default and Cancel Buttons « 2,000 Things You Should Know About WPF