Glass Wizzard

Glass Wizzard

  • NA
  • 2
  • 622

How do I detect when Enter is pressed in a TextBox?

Apr 14 2018 5:50 AM

Hi, take a look at this keydown event of my textbox:

  1. private void txtInput_KeyDown(object sender, KeyEventArgs e)  
  2. {  
  3.    if (e.Key == Key.Return)  
  4.       txtInput.Clear();  
  5. }  

 

Simple no? Well, I have wavy red lines beneath both "Key" words. I got that information from the msdn docs, so they, for whatever reason, are giving the wrong syntax.


I just want the textbox to clear when enter is pressed. Could someone help me out?

Thanks

The error is: "KeyEventArgs does not contain a definition for Key."

The second one (for the second "key" word) says "The name key does not exist in the current context".


Answers (2)