title: WPF Move element with mouse
body: <p>I am trying to move button with mouse in WPF app.</p>
  
  <p>There is XAML Grid which is a root of structure:</p>
  
  <pre><code>&lt;Grid Name="MyGrid"            &gt;
      &lt;Button Name="Samplebutton"
              PreviewMouseDown="Samplebutton_PreviewMouseDown"
              PreviewMouseUp="Samplebutton_PreviewMouseUp"
              PreviewMouseMove="Samplebutton_PreviewMouseMove"
              Content="Moving" Width="100" Height="35"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>And code behind:</p>
  
  <pre><code>private bool _isMoving;
  
  
  private void Samplebutton_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  {
      _isMoving = true;
  }
  
  private void Samplebutton_PreviewMouseUp(object sender, MouseButtonEventArgs e)
  {
      _isMoving = false;
  }
  
  private void Samplebutton_PreviewMouseMove(object sender, MouseEventArgs e)
  {
      if (!_isMoving) return;
  
      TranslateTransform transform = new TranslateTransform();
      transform.X = Mouse.GetPosition(MyGrid).X;
      transform.Y = Mouse.GetPosition(MyGrid).Y;
      this.Samplebutton.RenderTransform = transform;
  }
  </code></pre>
  
  <p>First click into button moves him far away and then I can move button, but for the first time the button is moved away. What I am missing?</p>