Assuming I have the following command
public class SignOutCommand : CommandBase, ISignOutCommand
{
private readonly UserModel _userModel;
private readonly IUserService _userService;
public SignOutCommand(IUserService userService)
{
_userService = userService;
_userModel = App.CurrentUser;
}
public bool CanExecute(object parameter)
{
var vm = parameter as EditProfileViewModel;
return vm != null;
}
public Task<bool> CanExecuteAsync(object parameter)
{
return Task.Run(() => CanExecute(parameter);
}
public void Execute(object parameter)
{
var vm = (EditProfileViewModel)parameter;
var signOutSucceeded = SignOutUser();
if (signOutSucceeded)
{
vm.AfterSuccessfulSignOut();
}
}
public Task ExecuteAsync(object parameter)
{
return Task.Run(() => Execute(parameter);
}
private bool SignOutUser()
{
// populate this so that we get the attached collections.
var user = _userService.GetByEmailAddress(_userModel.Email);
_userService.RevokeLoggedInUser(user);
return true;
}
}
And my XAML has a button
<Button Text="Sign out"
Command="{Binding SignOutCommand}"
CommandParameter="{Binding}" />
What would it take for this to execute the ExecuteAsync
instead of Execute
? Sorry if this is trivial, I'm quite new to XAML.
Also, I'm actually doing this in Xamarin.Forms XAML, not sure if it makes a difference here.