✅ RelayCommand CanExecute MVVM
Hi, I'm using this nuget
CommunityToolkit.Mvvm.Input
to add my relaycommand.
i've set CanExecute this way =>
AddThickCommand = new RelayCommand(AddThickCommand_Execute, () => CanAddThickness);
My problem there is that canexecute is trigger only when i declare AddThickCommand
and canexecute is never raised again even if the boolean CanAddThickness
change.
I'd like to update canexecute each time CanAddThickness
change to enable or not the button. Any idea why this don't work with this package ?4 Replies
You need to notify the command that the bool has changed
IRelayCommand.NotifyCanExecuteChanged
Since you are already using CommunityToolkit.Mvvm, you could use the source generated version of this to get all this "for free"
this would add a AddThicknessCommand
public property that has a CanExecute
that depends on the CanAddThickness
observable property. When that property changes, the command will re-evaluate if it can execute or not.oh didn't know we could add anotations with this nuget i'll take a look thanks !!
yea the source generator for it is... amazing
it writes all the boilerplate code for you
that is a bit tricky cause some code aren't wrote and you need to know that the properties is automatically generated, it will be perfect after sometime using it. Thanks !