#313 – Specify a Cancel Button in a Window

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>

.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #313 – Specify a Cancel Button in a Window

  1. Pingback: #314 – Typical Usage for Default and Cancel Buttons « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: