Skip to content

Why is the KeyDown event of TextBox not triggered?#

Because TextBox handles the KeyDown event internally. If you need to handle the event before TextBox processes it, you should register a tunnel event:

1
2
3
4
5
6
target.AddHandler(InputElement.KeyDownEvent, OnTextBoxKeyDown, RoutingStrategies.Tunnel);

void OnTextBoxKeyDown(object sender, KeyEventArgs e)
{
    // Write your codes here
}

💖 Provided by kongdetuo

🔗 Original Document Avalonia 常见问题

(Obtained permission from original author,Modified)