title: moving a textbox with mouse
body: <p>I have a custom WPF control which consist of single TextBox</p>
  
  <pre><code>&lt;UserControl HorizontalAlignment="Left" x:Class="WPFDiagramDesignerControl.Components.UcWBSBlock"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Height="100" Width="100" IsEnabled="True"&gt;
  
      &lt;Grid &gt;
          &lt;TextBox x:Name="txtBox" IsEnabled="True"   Background="AntiqueWhite"  Margin="10,10,10,10" TextWrapping="Wrap"&gt; &lt;/TextBox&gt;
      &lt;/Grid&gt;
  
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>The control is placed on Canvas called MyDesigner.</p>
  
  <p>I want to move my control on canvas only if I click on textbox and move mouse. I don't want to move control when I click on margin between borders of control and textbox.
  I started writting a code and it looks like that</p>
  
  <pre><code>public partial class UcWBSBlock : UserControl
  {
  
      bool textChanged = false;
      bool isClicked = false;
      Point startPoint;
      DesignerItem parentItem;
      DesignerCanvas parentCanvas;
  
      public UcWBSBlock()
      {
  
          InitializeComponent();
  
          txtBox.MouseDoubleClick+=new MouseButtonEventHandler(txtBox_MouseDoubleClick);
          txtBox.MouseMove+=new MouseEventHandler(txtBox_MouseMove);
          txtBox.PreviewMouseDown+=new MouseButtonEventHandler(txtBox_PreviewMouseDown);
          txtBox.PreviewMouseUp+=new MouseButtonEventHandler(txtBox_PreviewMouseUp);
          txtBox.Cursor = Cursors.SizeAll;
  
      }
  
      private void txtBox_MouseMove(object sender, RoutedEventArgs e)
      {
          if (isClicked)
          {
              Point mousePos = Mouse.GetPosition(parentCanvas);
  
              parentItem = this.Parent as DesignerItem;
              parentCanvas = parentItem.Parent as DesignerCanvas;
              Point relativePosition = Mouse.GetPosition(parentCanvas);
              DesignerCanvas.SetLeft(parentItem,DesignerCanvas.GetLeft(parentItem) -  (startPoint.X - mousePos.X));
              DesignerCanvas.SetTop(parentItem, DesignerCanvas.GetTop(parentItem) - (startPoint.Y - mousePos.Y));
          }  
      }
  
      private void txtBox_PreviewMouseDown(object sender, RoutedEventArgs e)
      {
          if (!isClicked)
          {
              isClicked = true;
              parentItem = this.Parent as DesignerItem;
              parentCanvas = parentItem.Parent as DesignerCanvas;
              startPoint = Mouse.GetPosition(parentCanvas);
          }
      }
  
      private void txtBox_PreviewMouseUp(object sender, RoutedEventArgs e)
      {
          isClicked = false;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However my control doesn't move :( What did I do wrong ?? It's hard to debug this :)</p>