C# wait for user to finish typing in a Text Box

前端 未结 15 1221
无人及你
无人及你 2020-11-27 18:16

Is there a way in C# to wait till the user finished typing in a textbox before taking in values they have typed without hitting enter?

Revised this question a little

15条回答
  •  [愿得一人]
    2020-11-27 18:39

    Most straight forward approach.

    *.xaml

    
    

    *.xaml.cs

    using System.Threading.Tasks;
    
    public bool isChanging = false;
    async private void Textbox1_TextChanged(object sender,
                                            TextChangedEventArgs e)
        {
            // entry flag
            if (isChanging)
            {
                return;
            }
            isChanging = true;
            await Task.Delay(500);
    
            // do your stuff here or call a function
    
            // exit flag
            isChanging = false;
        }
    

提交回复
热议问题