#312 – Specify a Default Button in a Window
June 2, 2011 4 Comments
You can use the IsDefault property to specify that a particular button in a window is the default button. You can still click on the button like you would any other button in the window, but if you press the ENTER key, the default button will respond as if it was clicked. The button responds to the ENTER 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" Click="Cancel_Click"/> </StackPanel>
Pingback: #314 – Typical Usage for Default and Cancel Buttons « 2,000 Things You Should Know About WPF
Pingback: #315 – Setting IsDefault and IsCancel to the Same Button « 2,000 Things You Should Know About WPF
Pingback: #847 – Default Button Behavior Depends on Focus | 2,000 Things You Should Know About WPF
Pingback: #848 – IsDefaulted vs. IsDefault for a Button | 2,000 Things You Should Know About WPF