#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