Last active
August 29, 2015 14:19
-
-
Save dimitrispaxinos/97be51bfcd766fc174d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// DisableableCommandAsync Constructor | |
/// </summary> | |
/// <param name="asyncExecute">Executing Delegate</param> | |
/// <param name="canExecute">Predicate for enabling/disabling</param> | |
/// <param name="disablables">List of IDisaeable Items to be disabled while executing</param> | |
/// <param name="disableWhileInProgress">Disable the Command itself while executing</param> | |
public DisableableCommandAsync(Func<object,Task> asyncExecute, | |
Predicate<object> canExecute, | |
IEnumerable<IDisableableCommand> disablables = null, | |
bool disableWhileInProgress = false) | |
: this(asyncExecute, canExecute) | |
{ | |
if (disablables != null) | |
{ | |
_disablables = disablables.ToList(); | |
if (disableWhileInProgress) | |
_disablables.Add(this); | |
} | |
} | |
public async void Execute(object parameter) | |
{ | |
if (_disablables != null) | |
{ | |
// disable IDisableable items while executing | |
using (var scope = new DisablingScope(_disablables)) | |
{ | |
await ExecuteAsync(parameter); | |
} | |
CommandManager.InvalidateRequerySuggested(); | |
} | |
else | |
await ExecuteAsync(parameter); | |
} | |
protected virtual async Task ExecuteAsync(object parameter) | |
{ | |
await _asyncExecute(parameter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment