Is it just me, or does binding a command with the optional CanExecute
property not work?
Xamarin Forms 3.5.0.129452 - Current on 07feb2019
In this case the button never enables.
<Button
Command="{Binding CopyFilesCommand}"
Text="Copy" />
private ICommand _CopyFilesCommand;
public ICommand CopyFilesCommand
{
get { return _CopyFilesCommand ?? (_CopyFilesCommand = new Command(On_CopyFilesCommand, (x) => CanCopyFiles)); }
}
public bool CanCopyFiles
{
get
{
//Logic to determine true or false
}
}
Property being used as the deciding factor is calling both OnPropertyChanged as well as Command.ChangeCanExecute
So a SelectedPath property changes - it yells out that the command should be re-evaluted for 'can' or 'cannot'
OnPropertyChanged(nameof(CanCopyFiles));
((Command)CopyFilesCommand).ChangeCanExecute();
In this case the button never enables.
However if I add one simple line to the XAML and manually bind the IsEnabled
to the exact same property - THEN the button enables and disables as expected - proving that all the other code is right.
<Button
Command="{Binding CopyFilesCommand}"
IsEnabled="{Binding CanCopyFiles}"
Text="Copy" />
Its an easy work around... But the point is that just binding to the command should be enough, provided the command is created knowing what property controls its can
factor. Right?