1

I'm working with MVVM Light Toolkit, and I'd like to create a RelayCommand.

If my ViewModel has some String properties, which ones call the RaiseCanExecuteChanged in the setters, everything works fine, the command can be executed when I want.

But if I change the code, I create a Model class X, and it contains all of these properties, the ViewModel contains a property with type X, where should I call the RaiseCanExecuteChanged? In the Model class makes no sense, and the setter of the X in the ViewModel is not called.

Aaaaaaaa
  • 2,015
  • 3
  • 22
  • 40

1 Answers1

4

You will likely need to subscribe to the Model class PropertyChanged event, and raise your RaiseCanExecuteChanged when the model property changes.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • So simple and obvious... Thanks! – Aaaaaaaa Feb 22 '12 at 21:30
  • @Vishal In the VM constructor, when you set the model, do something like `model.PropertyChanged += (o,e) => this.command.RaiseCanExecuteChanged();` – Reed Copsey Jun 03 '16 at 17:41
  • I have tried that but still CanExecute method does not fire. I have a Property Called NewOrder in my VM which is of type Order. Inside order I have 3-4 simple string and int properrties and a property of type ICollection. So, is there any extra work needed for me to do here?? – Vishal Jun 03 '16 at 17:56