title: Getting Window from view model
body: <p>I have created a custom messageBox Window to replace the typical MessageBox.</p>
  
  <p>My custom messageBox (child Window) needs parent window to be passed as an argument. The parent window is where child window will be located within in the location specified (Top Left, Top Center, etc.) also as an argument.</p>
  
  <p>So when calling my custom messageBox from view model, I need to get the Window to pass it through. How can I get the Window associated to the view model?</p>
  
  <p>Maybe using an Interface like commented <a href="https://codereview.stackexchange.com/questions/58240/access-view-from-current-corresponding-viewmodel">here</a>? I am trying to implement it but this.DataContext.View does not exist.</p>
  
  <p>I am using Visual Studio 2008.</p>
  
  <p><strong>ATTEMPT #1</strong>: mm8 solution</p>
  
  <pre><code>&lt;Window x:Class="MyNamespace.Main"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:viewmodel="clr-namespace:MyNamespace.ViewModels"&gt;
      &lt;Window.Resources&gt;
          &lt;viewmodel:MainViewModel x:Key="wMainViewModel" /&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid DataContext="{StaticResource wMainViewModel}"&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Taken into account that I initialize DataContext from xaml and not in code-behind from constructor, how can I pass the view to the view model¿?</p>