据我所知,下面的代码可以从 Relay/ICommand Command 更改为 Delegate 命令,并且仍然以相同的方式绑定命令!如果我错了,它们的区别和用途是什么。
private DelegateCommand something;
public DelegateCommand Something
这是完整的实现
private RelayCommand something;
public ICommand Something
{
get
{
if (something == null)
something = new RelayCommand(SomethingMethod, CanSomething);
return something;
}
}
private bool CanSomething(object parameter)
{
//just for readability return true
return true;
}
private void SomethingMethod(object parameter)
{
using (DatabaseContext context = new DatabaseContext())
{
try { }
catch(Exception ex)
{
throw new ApplicationException(string.Format("Something {0} to {1}", file, directory), ex);
}
}
}