Select to view content in your preferred language

KeyDown

2721
2
03-25-2011 10:48 AM
JoannaLaroussi
Emerging Contributor
I am trying to capture key down event in my text box. In general, I am expecting the user to enter in the text box a number, which will be later queried and start my query operation after Enter key will be pressed. In C#  I will do it simple like this:

private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
   //do my query

            }
        }

But this solution does not work in Silverlight. Does anybody found a solution for this problem?
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
This should also work in Silverlight if yourTextBox has Focus.
private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
 if (e.Key == System.Windows.Input.Key.Enter)
  System.Diagnostics.Debug.WriteLine(e.Key);
}
0 Kudos
JoannaLaroussi
Emerging Contributor
Thank you for your answer. I was able solve the problem in the following way:
private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                //do my query
            }

        }
0 Kudos