title: Dragging window in MVVM
body: <p>I have custom window in WPF. I want to implement dragging without violeting MVVM pattern. So I have transparent rectangle on the top, with OnMouseDown event, handled in code-behind:</p>
  
  <pre><code>    private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
      {
          if (e.ChangedButton == MouseButton.Left)
              this.DragMove();
      }
  </code></pre>
  
  <p>Simple. But is it good approach?</p>
  
  <p>I have idea to move this code to ViewModel. Call it via Command, like this:</p>
  
  <pre><code>    &lt;Rectangle x:Name="DragRectangle" VerticalAlignment="Top" Height="30" Fill="Transparent"&gt;
          &lt;Rectangle.InputBindings&gt;
              &lt;MouseBinding Gesture="LeftClick" Command="{Binding DragCommand}"/&gt;
          &lt;/Rectangle.InputBindings&gt;
      &lt;/Rectangle&gt;
  </code></pre>
  
  <p>But then, I need to have "this" (so Window) in ViewModel. I'm not sure if that's possible (and if so, if that's a good practice).</p>
  
  <p>How should I implement dragging custom window so it will not violate MVVM pattern?</p>