George Hernando
George Hernando

Reputation: 2630

WPF/C#/XAML IsDefault Button

I have a button defined in XAML as follows:

<Button IsDefault="True" FontSize="12" Margin="312,16,155,3.6" Height="28" Name="SaveButton" Width="99" Click="SaveButton_Click">Save</Button>

In my SaveButton_Click method, I received two arguments: the sender and the event.

Is it possible to determine whether or not the submit method was invoked because of a click on the button or because of hitting the Enter key?

Upvotes: 0

Views: 216

Answers (1)

Med.Amine.Touil
Med.Amine.Touil

Reputation: 1235

Yes You can.

           if (InputManager.Current.MostRecentInputDevice is KeyboardDevice)
                MessageBox.Show("Enter key");
            else
                MessageBox.Show("Mouse click");

Upvotes: 2

Related Questions