Michael Gaigg: Über UI/UX Design

2Aug0

Silverlight Form Submission using the Enter Key

Posted by Michael Gaigg

Sounds ridiculously simple but still I need to look it up over and over again.

So here it is, documented once and forever: How to catch the Enter key (to trigger a search form submission for example).

XAML:

<TextBox x:Name="txtInputField" KeyUp="txtInputField_KeyUp" />

Code-behind (C#):

private void txtInputField_KeyUp(object sender, KeyEventArgs e)
{
   if ((e.Key == Key.Enter) && (txtInputField.Text.Length > 3)) // feel free to remove the length limit
   {
      // submit form or whatever you want to do
      this.SubmitForm();
   }
}

Note: I've added a clause so that the form is only submitted when the user has typed a minimum of 3 characters which makes sense when hitting a service for example. Feel free to remove that.

23Apr0

Highlights of Week 16/2011

Posted by Michael Gaigg

18Mar0

Highlights of Week 11/2011

Posted by Michael Gaigg

Thanks to everybody that sent me link suggestions. Here the highlights for week 11/2011: