title: WPF MVVM Modal Overlay Dialog only over a View (not Window)
body: <p>I'm pretty much new to the MVVM architecture design...</p>
  
  <p>I was struggling lately to find a suitable control already written for such a purpose but had no luck, so I reused parts of XAML from another similar control and got make my own.</p>
  
  <p>What I want to achieve is:</p>
  
  <p>Have a reusable View (usercontrol) + viewmodel (to bind to) to be able to use inside other views as a modal overlay showing a dialog that disables the rest of the view, and shows a dialog over the it. </p>
  
  <p><img src="https://i.stack.imgur.com/jLA5d.png" alt="enter image description here"></p>
  
  <p>How I wanted to implement it:</p>
  
  <ul>
  <li>create a viewmodel that takes string(message) and action+string collection(buttons)</li>
  <li>viewmodel creates a collection of ICommands that call those actions</li>
  <li>dialog view binds to the its viewmodel that will be exposed as property of another viewmodel (parent)</li>
  <li>dialog view is put into the xaml of the parent like this:</li>
  </ul>
  
  <p>pseudoXAML:</p>
  
  <pre><code>    &lt;usercontrol /customerview/ ...&gt;
         &lt;grid&gt;
           &lt;grid x:Name="content"&gt;
             &lt;various form content /&gt;
           &lt;/grid&gt;
           &lt;ctrl:Dialog DataContext="{Binding DialogModel}" Message="{Binding Message}" Commands="{Binding Commands}" IsShown="{Binding IsShown}" BlockedUI="{Binding ElementName=content}" /&gt;
        &lt;/grid&gt;
      &lt;/usercontrol&gt;
  </code></pre>
  
  <p>So here the modal dialog gets the datacontext from the DialogModel property of the Customer viewmodel, and binds commands and message. It would be also bound to some other element (here 'content') that needs to be disabled when the dialog shows (binding to IsShown). When you click some button in the dialog the associated command is called that simply calls the associated action that was passed in the constructor of the viewmodel.</p>
  
  <p>This way I would be able to call Show() and Hide() of the dialog on the dialog viewmodel from inside the Customer viewmodel and alter the dialog viewmodel as needed.</p>
  
  <p>It would give me only one dialog at a time but that is fine.
  I also think that the dialog viewmodel would remain unittestable, since the unittests would cover the calling of the commands that ought to be created after it being created with Actions in the constructor. There would be a few lines of codebehind for the dialog view, but very little and pretty dumb (setters getters, with almost no code).</p>
  
  <p>What concerns me is:</p>
  
  <p>Is this ok?
  Are there any problems I could get into?
  Does this break some MVVM principles?</p>
  
  <p>Thanks a lot!</p>
  
  <p>EDIT: I posted my complete solution so you can have a better look. Any architectural comments welcome. If you see some syntax that can be corrected the post is flagged as community wiki.</p>