#312 – Specify a Default Button in a Window

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>

.

Advertisements