据我所知,下面的代码可以从Relay/ICommand命令更改为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);
}
}
}
RelayCommand
和DelegateCommand
? - Reed Copsey