我有点坚持正确使用Telerik.Windows.Controls DelegateCommand
我有以下设置,可以编译,但我更关心的是,我是否正确使用它。我已经在 Online Doc 中搜索了一段时间,但找不到任何示例。
特别是,我对如何使用CanSaveAuthorization
或底层CanExecute
以及如何处理所需的 object 参数感到困惑。
谢谢,
public class CreateAuthorizationViewModel : ViewModelBase
{
private Authorization authorization;
private AuthorizationRepository authorizationRepository;
private DelegateCommand saveAuthorizationCommand;
public DelegateCommand SaveAuthorizationCommand
{
get
{
return saveAuthorizationCommand;
}
}
public CreateAuthorizationViewModel()
{
InitializeCommand();
}
private void InitializeCommand()
{
saveAuthorizationCommand = new DelegateCommand(SaveAuthorization, CanSaveAuthorization);
}
private void SaveAuthorization(object parameter)
{
authorizationRepository.Save();
}
private bool CanSaveAuthorization(object parameter)
{
//I would have validation logic here
return true;
}
}