我的视图上有一个带有简单命令绑定的按钮:
<Window ...>
<Window.DataContext>
<vm:ShellViewModel />
</Window.DataContext>
...
<Button Command="{Binding DoSomethingCoolCommand}" Content="Execute" />
和虚拟机:
public class ShellViewModel : ObservableObject {
private RelayCommand _doSomethingCoolCommand;
public ICommand DoSomethingCoolCommand {
get {
return _doSomethingCoolCommand ??
(_doSomethingCoolCommand = new RelayCommand(DoSomethingCool));
}
}
private void DoSomethingCool() { ... }
但是,该按钮在应用程序/视图启动时被禁用,我无法启用它。我尝试将命令执行评估传递给RelayCommand
并设置IsEnabled
在视图上。我错过了什么吗?
编辑
RelayCommand 和 ObservableObject 来自mvvm 基础项目,如标签中所述。链接:https ://mvvmfoundation.codeplex.com