title: WPF MVVM: How to close a window
body: <p>I have a <code>Button</code> that closes my window when it's clicked:</p>
  
  <pre><code>&lt;Button x:Name="buttonOk"  IsCancel="True"&gt;Ok&lt;/Button&gt;
  </code></pre>
  
  <p>That's fine until I add a <code>Command</code> to the <code>Button</code> i.e.</p>
  
  <pre><code>&lt;Button x:Name="buttonOk" 
          Command="{Binding SaveCommand}" 
          IsCancel="True"&gt;Ok&lt;/Button&gt;
  </code></pre>
  
  <p>Now it doesn't close presumably because I am handling the <code>Command</code>. I can fix this by putting an <code>EventHandler</code> in and calling <code>this.Close()</code> i.e. </p>
  
  <pre><code>&lt;Button x:Name="buttonOk" 
          Click="closeWindow" 
          Command="{Binding SaveCommand}" 
          IsCancel="True"&gt;Ok&lt;/Button&gt;
  </code></pre>
  
  <p>but now I have code in my code behind i.e. the method <code>SaveCommand</code>. I am using the MVVM pattern and <code>SaveCommand</code> is the only code in my code behind. </p>
  
  <p>How can I do this differently so as not to use code behind?</p>