Search code examples
uwptextboxwin-universal-app

KeyDown Event not fired for TextBox in UWP


When I press the Enter key, the KeyDown event for the TextBox is not fired if its AcceptsReturn property is set to true. How can I identify when the Enter key is pressed for a TextBox with AcceptsReturn set to true?


Solution

  • I tried the below code, and its works for me,

    var textBox = new TextBox();
    KeyEventHandler keyeventHandler = new KeyEventHandler(textBox_KeyDown);
    
    textBox.AddHandler(TextBox.KeyDownEvent, keyeventHandler, true);
    
    private void textBox_KeyDown(object sender, KeyEventArgs e)
    {
    *** now Enter Key gets fired eventhough when i set AcceptsReturn as True ***
    }