【发布时间】:2018-08-10 06:21:24
【问题描述】:
我的 Command-ViewModel 中是否缺少某些内容?
public class Command : ICommand
{
public Command(Action execute, Func<bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute ?? new Func<bool>(() => true);
}
private Action execute;
private Func<bool> canExecute;
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return canExecute.Invoke();
}
public void Execute(object parameter)
{
execute?.Invoke();
}
}
每次我想在我的MainViewModel 中使用CanExecuteChanged 和这行代码((Command)MyCommand).CanExecuteChanged(); 它都会给我这个错误The event 'Command.CanExecuteChanged' can only appear on the left hand side of += or -=
【问题讨论】:
标签: c# xamarin.forms