Wednesday, April 28, 2010

Key Press Event For Silverlight Textbox

This how we need to do to capture Key Press Event for Sliverlight text box. Attach KeyDown Event in XMAL code in MainPage.xaml file.

 

<TextBox x:Name="customer_name"

KeyDown="customer_name_KeyDown" VerticalAlignment="Top" TextWrapping="Wrap" FontSize="10.667" Width="120" Height="22"/>


In the codebehind you can check with the Key value like example shown below in MainPage.xaml.cs file.

private void customer_name_KeyDown(object sender, KeyEventArgs e)
        {
         
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
            }
            else
            {
                e.Handled = false;
            }
        }
 

No comments:

Post a Comment