title: How to call functions in a main view model from other view models?
body: <p>My program is composed of a <code>TreeView</code> and two <code>contentPresenters</code> at ground level. The mainWindow, <code>TreeView</code>, and each <code>contentPresenter</code> all have their own viewModels.</p>
  
  <p><strong>I would like to call a function in the <code>mainWindowViewModel</code> from the <code>TreeViewViewModel</code>.</strong></p>
  
  <p>I need to do this because the <code>mainWindowViewModel</code> controls what is displayed in the <code>contentPresenters</code>, and I would like to manually update the display.</p>
  
  <p>I'm guessing I would do something like this...</p>
  
  <p><strong><code>TreeViewViewModel</code>:</strong></p>
  
  <pre><code>public class TreeViewViewModel
  {
       //Do I need to declare the MainWindowVM?
  
       public TreeViewViewModel() { ... }
  
       private void function()
       {
            //Command that affects display
  
            //Manually call function in MainWindowVM to refresh View
       }
  }
  </code></pre>
  
  <p>I have tried to get access to the <code>MainWindowVM</code> from the <code>TreeViewViewModel</code> by using:</p>
  
  <pre><code>public MainWindowViewModel ViewModel { get { return DataContext as MainWindowViewModel; } }
  </code></pre>
  
  <p>But it doesn't make much sense. because the MWVM is not the <code>DataContext</code> of the <code>TreeViewViewModel</code>.</p>