您必須實施DelegateCommand<T>
因此,通過另一Func<T,bool>
在構造和CanExecute()
方法的返回按位與(& &)canExecute
代表和canSee
委託。
public class DelegateCommand<T> : ICommand
{
private readonly Action<T> executeMethod;
private readonly Func<T, bool> canExecuteMethod;
private readonly Func<T, bool> canSeeMethod;
public DelegateCommand(Action<T> executeMethod) : this(executeMethod, null)
{}
public DelegateCommand(Action<T> executeMethod,
Func<T, bool> canExecuteMethod)
: this(executeMethod, canExecuteMethod, null)
{}
public DelegateCommand(Action<T> executeMethod,
Func<T, bool> canExecuteMethod,
Func<T, bool> canSeeMethod)
{
this.executeMethod = executeMethod;
this.canExecuteMethod = canExecuteMethod;
this.canSeeMethod = canSeeMethod;
}
...... //Other implementations here
public bool CanExecute(T parameter)
{
if (canExecuteMethod == null) return true;
return canExecuteMethod(parameter) && canSeeMethod(parameter);
}
}
這幾乎與我所做的一樣。我的問題是如何在xaml中使用它 – user436862
您可以更詳細地描述語句「在XAML中如何使用」?我們只在UI中綁定命令。 –