Skip to content

How to disable button during it's binded task excute? #13637

Answered by stevemonaco
hahanonym asked this question in Q&A
Discussion options

You must be logged in to vote

If you're using Mvvm Toolkit, this happens by default as AllowConcurrentExecutions is false by default. eg.

[RelayCommand]
public async Task DoTheThing()
{
    await Task.Delay(2000);
}
<Button Command="{Binding DoTheThingCommand}" Content="Click" />

Otherwise, you need to: manage some state within the body of the command (eg. bool IsExecuting), have your command implementation raise CanExecuteChanged, do your task, reset state, raise CanExecutiveChanged again so the button is re-enabled. Might be a cleaner way, but depends on ICommand implementation.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@stevemonaco
Comment options

Answer selected by hahanonym
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants