imran
imran

Reputation: 59

How to add enter key event on a button

I have a button in XAML here:

<Button Content="Login" x:Name="loginButton" Grid.Row="7" Grid.Column="3"
        Margin="200,30,0,0" Grid.RowSpan="2" Height="50" Width="150"
        VertialAlignment="Top" Click="loginButton_Click" ClickMode="Press"
        FontSize="24" FontFamily="Calibri" Style="{StaticResource AlbaabButtonStyle}">
</Button>

When user hits the enter key, he must be logged in to his account. How do I generate a press enter key event in c#?

Upvotes: 0

Views: 974

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101742

Set Button.IsDefault property to true then just handle the button click event.Pressing ENTER will trigger your default button's click event after you set IsDefault true..

Upvotes: 2

Related Questions