Button disabling while method execution (PreviewLeftMouseDown/Up must be workable)

前端 未结 1 1040
后悔当初
后悔当初 2021-01-28 18:00

I need a sequence as follows:

  • button default state
  • button Down, \"methods for button Down\" execute and Button itself is disabled for a time.
  • but
相关标签:
1条回答
  • 2021-01-28 18:22

    You could do this more easily in an async Click handler:

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        var button = (Button)sender;
        button.IsEnabled = false;
    
        await Task.Run(() =>
        {
            // perform time-consuming action
            Thread.Sleep(5000); // just for test
        });
    
        button.IsEnabled = true;
    }
    
    0 讨论(0)
提交回复
热议问题