title: WPF: How to translateTransform a rectangle?
body: <p>I'm trying to move a rectangle drawn in Canvas by mouse  (drag and drop).</p>
  
  <p>When I click on the Rectangle and move the mouse (keep clicking) to a new position it's OK:</p>
  
  <p><a href="https://i.stack.imgur.com/Gy7OE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gy7OE.png" alt="enter image description here"></a></p>
  
  <p>But when I click on it again and move the mouse just a bit the Rectangle move to old position:</p>
  
  <p><a href="https://i.stack.imgur.com/GPfHg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GPfHg.png" alt="enter image description here"></a></p>
  
  <p>I don't know why it is. Can anybody give me some explaination?</p>
  
  <p>Here is my code (all parameters have been assigned and initialized).
  Thanks in advance!</p>
  
  <pre><code>private void MyCanvas_MouseMove_1(object sender, MouseEventArgs e)
          { 
              if (e.RightButton == MouseButtonState.Pressed &amp;&amp; e.OriginalSource is Shape)
              {
                  p2 = e.GetPosition(MyCanvas);
                  TranslateTransform tf = new TranslateTransform(p2.X - p1.X, p2.Y - p1.Y);
                  _MyTestRect.RenderTransform = tf;
              }
  
          }
  private void MyCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
          {
  
              if (e.OriginalSource is Shape)
              {
                  p1 = e.GetPosition(MyCanvas);
              }
  
          }
  </code></pre>