title: How to Call a Method from another ViewModel in a View (WPF)
body: <p>I have my (Mainwindow) Window.xaml.cs in which i declare a custom closing Event. In that Closing event I would like to call a method from another Views' ViewModel ReportGeneratorViewModel.cs. I don't know how to link those 2 together or call it from there. (The ReportGeneratorView is hosted in a frame control in the Window.xaml)</p>
  <p>Normaly my Views.xaml.cs call methods from corresponding ViewModels via</p>
  <pre><code>var Context = (ViewModel)DataContext;
  Context.CallMethod();
  </code></pre>
  <p>So my Idea was that i just call the <code>DesiredMethod()</code> in my window.xaml.cs like that:</p>
  <pre><code>var Context = (ReportGeneratorViewModel)DataContext;
  Context.DesiredMethod();
  </code></pre>
  <p>But it throws an exception that &quot;...WindowViewModel&quot; can not be converted to &quot;...ReportGeneratorViewModel&quot;.</p>
  <p>Is there any way to go about that?</p>