0

I am using Josh Smith's RelayCommand in my WPF MVVM application.

I have a ViewModel. Inside that I have a reference to another ViewModel.

The child ViewModel has a property of type ICommand in it.

In my parent ViewModel, can I add one more condition to the "CanExecute" predicate?

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
Relativity
  • 6,690
  • 22
  • 78
  • 128

1 Answers1

0

You have at least two choices:

  1. You can expose a new ICommand from the parent viewmodel that uses the child viewmodel in its implementation of CanExecute of the new command.
  2. You can add a reference to the parent viewmodel in the child and call a method on the parent in the child's implementation of CanExecute.

The second option might look something like this in the child:

SampleCommand = new RelayCommand(..., param => ChildSampleCanExecute() && parentViewModel.ParentSampleCanExecute());
Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • Is there anyway that I can assign true/false to chldViwmodel's CanExecute from parent viewmodel ?...Or..Can I add one more condition to the child viewmodel's can execute preducate from parent viewmodel ? – Relativity Dec 25 '10 at 05:59