Reputation:
I want CanExecute
to turn to true
when my 5 entries are validated.
Right now I've got this which is binded to my send-button
SendCommand = new Command(() => SendData());
I got no idea how to use CanExecute and how to set this value to true when all 5 entries are validated.
Has somebody a reference or an advice?
Upvotes: 0
Views: 78
Reputation:
I got it thanks to @Scott Chamberlain. Sorry for the dumb question .... it was as easy as you would expect.
SendCommand = new Command(() => SendData(),() => CanSend());
Edit: Make sure you add the EventHandler
and raise him in the setters of your booleans.
public event EventHandler CanExecuteChanged;
I did it like that:
public bool CanExecute()
{
if (IsValid1 && IsValid2 && IsValid3 && IsValid4 && IsValid5)
{
return true;
} else
{
return false;
}
}
and like
public bool IsValid1
{
get => _isvalid1;
set
{
_isvalid1 = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsValid1)));
((Command)SendCommand).ChangeCanExecute();
}
}
Upvotes: 1