title: How to excecute a command declared in child viewmodel in an MVVM app?
body: <p>I've got a MainWindowVM and multiple child viewmodels inheriting from it. 
  MainWindowVM inherits from ViewModelBase which implements INotifyPropertychanged.</p>
  
  <p>Each view has DataContext set to CurrentViewModel defined in MainWindowVM and every button
  has got a binding to a command.</p>
  
  <p>If I put the commands (and other command-handling code in the constructor) in the MainWindowVM,
  button clicks in every view works as expected. I set MainControlVM as CurrentViewModel in the constructor of MainWindowVM. 
  Except for MainControlVM and MainWindowVM, setting commands in any other VM means they wont execute. </p>
  
  <p>However, I want to have commands only in the VMs they are used.</p>
  
  <p>I  found many tutorials on MVVM with only one or two viewmodels so this situation isnt an issue for them.</p>
  
  <p>Edit including code:
  This is the relevant code:</p>
  
  <p>Part of one of the child views in XAML with a binding:</p>
  
  <pre><code>&lt;Grid  DataContext="{Binding CurrentViewModel}" Margin="0,0,-186,0"&gt;
      &lt;Button Content="Add" HorizontalAlignment="Left" Margin="25,249,0,0" VerticalAlignment="Top" Width="62" Height="32" 
  Command="{Binding AddCategoryVMCommand}" /&gt;
  </code></pre>
  
  <p>MainWindowVM class contains:</p>
  
  <pre><code>   public ICommand AddCategoryVMCommand { get; private set; }
  </code></pre>
  
  <p>and, in the constructor:</p>
  
  <pre><code>AddCategoryVMCommand = new RelayCommand(() =&gt; ExecuteAddCategoryVMCommand());                   
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>    protected void ExecuteAddCategoryVMCommand()
      {
          CurrentViewModel = new AddCategoryVM();
      }
  </code></pre>
  
  <p>....and the same kind of code for each command. Aso, CurrentViewModel is set in the MainWindowVM class. This is the property that the MainWindow view uses to determine which view to display along with a datatemplate: </p>
  
  <pre><code>        public ViewModelBase CurrentViewModel
      {
          get { return _currentViewModel; }
          set
          {
              if (_currentViewModel == value)
                             return;
              _currentViewModel = value; 
              this.RaiseNotifyPropertyChanged("CurrentViewModel");
          }
      }
  </code></pre>
  
  <p>How can I make commands execute when declared in child viewmodel?</p>