How to create submit button in WPF?

When you press Enter anywhere in the HTML form , it runs its action , which is equivalent to clicking the submit button. How to make a window, when I press Enter anywhere, it raises an event?

+44
submit wpf keypress
Nov 16 '10 at 13:13
source share
2 answers

Set the IsDefault property to true to enable the Enter key to activate the action of this button. There is also an IsCancel property that does the same for the Escape key.

+82
Nov 16 '10 at 13:53
source share

Assign a PreviewKeyDown event to the window in XAML, then check the KeyEventArgs in the code to determine if the user has pressed the Enter key.

XAML Code:

 <Window [...] PreviewKeyDown="Window_PreviewKeyDown"> 

Code behind:

 private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { // Whatever code you want if enter key is pressed goes here } } 
+6
Nov 16 '10 at 13:17
source share



All Articles