16/11/11 07:08:21.41 KgVthd+h.net
いい例がある。これならわかる。これを逃してしてしまうと永久にわからないというほどの
優れた例を提示しておく。
優れた例
XAML
<TextBox Text="{Binding Name}"/>
<Button Content="実行" Command="{Binding ExecuteCommand}"/>
<Label Content="{Binding Result}"/>
ViewModel
public DelegateCommand ExecuteCommand { get; }
public MainWindowViewModel(){
ExecuteCommand = new DelegateCommand(() => Result = "登録OK", CanExecute);
}
private bool CanExecute(){
return !string.IsNullOrWhiteSpace(Name);
}
private string _name;
public string Name{
get { return _name; }
set { if (OnPropertyChanged(ref _name, value)) ExecuteCommand.RaiseCanExecuteChanged();}
}