Don't raise TextChanged while continuous typing

后端 未结 12 1268
闹比i
闹比i 2020-12-14 10:09

I have a textbox that has a fairly hefty _TextChanged event handler. Under normal typing condition the performance is okay, but it can noticeably lag when the u

12条回答
  •  我在风中等你
    2020-12-14 10:38

    I played with this for a while. To me this was the most elegant (simple) solution I could come up with:

        string mostRecentText = "";
    
        async void entry_textChanged(object sender, EventArgs e)
        {
            //get the entered text
            string enteredText = (sender as Entry).Text;
    
            //set the instance variable for entered text
            mostRecentText = enteredText;
    
            //wait 1 second in case they keep typing
            await Task.Delay(1000);
    
            //if they didn't keep typing
            if (enteredText == mostRecentText)
            {
                //do what you were going to do
                doSomething(mostRecentText);
            }
        }
    

提交回复
热议问题