KeyUp event is doubling using “mahapps.metro”

给你一囗甜甜゛ 提交于 2019-12-06 08:32:53

Well, I have submitted your code to different tests and the method is not duplicated...

int i = 0;
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    if(((TextBox)sender).Text != string.Empty)
    {
        System.Diagnostics.Debug.WriteLine("Hello " + ++i);
    }
 }

Verify that another active control has no associated keyboard event, that may be the problem.

I have tested your code and it works well

As you told me in the chat, you quickly press backspace + 1, well, the error is that your code detects the pulsation of any key as long as the TextBox is not empty, so, what you must do is restrict the use of Back

private void Textbox_KeyUp(object sender, KeyEventArgs e)
{
    if (textbox.Text != string.Empty && e.Key != Key.Back)
     {
         this.ShowMessageAsync("This is the title", "Some message");
     }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!