'How to make a Button enabled using FreshAwaitCommand (FreshMVVM) in Xamarin.Forms?
I use FreshAwaitCommand to prevent a command executing (and also make the button unavailable) until certain conditions are met. Everything works fine, except that the visual state of the button does not change, but when the button is clicked, the command is executed. I can't figure out what I'm doing wrong.
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class SignupPageModel : FreshBasePageModel
{
public ICommand ValidateCommand { get; private set; }
public FreshAwaitCommand SignUpCommand { get; private set; }
public SignupPageModel()
{
SignUpCommand = new FreshAwaitCommand(async (obj) =>
{
await SignUpCommandHandler();
obj.SetResult(true);
},
canExecute : new Func<bool>(ValidateSignUpData));
ValidateCommand = new Command<string>(ValidateCommandHandler);
}
private bool ValidateSignUpData()
{
// checks if command can be executed
// returns True or False
}
private void ValidateCommandHandler(string field)
{
// checking data ...
// ...
SignUpCommand.ChangeCanExecute();
}
}
XAML code snippet:
<Entry
Placeholder="Enter username"
<Entry.Behaviors>
<xct:UserStoppedTypingBehavior
Command="{Binding ValidateCommand}"
CommandParameter="username"/>
</Entry.Behaviors>
</Entry>
<Button Command="{Binding SignUpCommand}"/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
