#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>

.

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

4 Responses to #312 – Specify a Default Button in a Window

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

  2. Pingback: #315 – Setting IsDefault and IsCancel to the Same Button « 2,000 Things You Should Know About WPF

  3. Pingback: #847 – Default Button Behavior Depends on Focus | 2,000 Things You Should Know About WPF

  4. Pingback: #848 – IsDefaulted vs. IsDefault for a Button | 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: