title: How to set margin to position element at the mouse cursor
body: <p>I cannot seem to figure out how to set the margins correspond to where the mouse cursor is at.</p>
  
  <p>Sample code:</p>
  
  <pre><code>protected override void OnMouseMove(MouseEventArgs e)
  {
    base.OnMouseMove(e);
  
    Connector connector = this.Template.FindName("PART_Connector", this) as Connector;
    double marginLeft = e.GetPosition(this).X - (connector.Width / 2);
    double marginTop = e.GetPosition(this).Y - (connector.Height / 2);
  
    connector.Margin = new Thickness(marginLeft, marginTop, 0, 0);
  }
  </code></pre>
  
  <p>The connector positioned using margin is always off from where it is supposed to be.</p>
  
  <p>Any good advice?</p>
  
  <hr>
  
  <p>If I set the margin like this, it will work but the connector is diminished to a single point. I want the connector to be 12x12</p>
  
  <pre><code>marginLeft = e.GetPosition(this).X;
  marginTop = e.GetPosition(this).Y;
  marginRight = this.DesiredSize.Width - e.GetPosition(this).X;
  marginBottom = this.DesiredSize.Height - e.GetPosition(this).Y;
  
  connector.Margin = new Thickness(marginLeft, marginTop, marginRight, marginBottom);
  </code></pre>
  
  <p>When I rescale the margins to provide the space for the connectors, the connectors just disappear:</p>
  
  <pre><code>marginLeft = e.GetPosition(this).X - (connector.Width / 2);
  marginTop = e.GetPosition(this).Y - (connector.Height / 2);
  marginRight = this.DesiredSize.Width - e.GetPosition(this).X + (connector.Width / 2);
  marginBottom = this.DesiredSize.Height - e.GetPosition(this).Y + (connector.Height / 2);
  </code></pre>
  
  <p>Appreciate any help here.</p>