title: Positioning an element inside the Canvas by its center (instead of the top left corner) using only XAML in WPF
body: <p>The common question about positioning an element inside a <code>Canvas</code> is "How to position the center of element (instead of the top left corner)".</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/3423834/wpf-resizing-a-circle-keeping-the-center-point-instead-of-topleft">WPF: Resizing a circle, keeping the center point instead of TopLeft?</a></li>
  <li><a href="https://stackoverflow.com/questions/5422897/wpf-center-ellipse-at-x-y">WPF Center Ellipse at X, Y</a></li>
  <li><a href="https://stackoverflow.com/questions/3682111/wpf-element-positioning-on-a-canvas">WPF element positioning on a Canvas</a> </li>
  </ul>
  
  <p>Several solutions are presented, but they all have drawbacks.</p>
  
  <p>The easiest solution is to accommodate the element size during while setting the <code>Canvas.Left</code> and <code>Canvas.Top</code> properties programmatically. This works, but only once. This solution doesn't support bindings and it will break when the element size is changed. You also cannot set the <code>Canvas.Left</code> or <code>Canvas.Top</code> using </p>
  
  <p>Another set of solutions involve translate transformations utilizing either <code>RenderTransform</code> or <code>Margin</code>. These solutions require binding some property to the <code>-0.5 * Width</code> or <code>-0.5 * Height</code>. Such binding requires creating a custom <code>ValueConverter</code> and is impossible to create using only XAML.</p>
  
  <p><strong>So, is there a simple way to position an element inside canvas so that its <code>Canvas.Left</code> and <code>Canvas.Top</code> correspond to the element's center and both size and position properties can be bound to some other properties?</strong></p>