title: Standard draw-on-canvas program, offset caused by docked UI elements. How to dynamically compensate?
body: <p>I'm learning WPF, and made (following a couple SO posts) a simple program where you draw with the mouse.  I have a DockPanel with top and left panes, and the drawing canvas taking up the remaining space.  When I click and drag to draw freeform curves, the drawing of the line is offset by the amount of space taken up by the menus.  I'd rather not hardcode values, since those sizes are liable to change.</p>
  
  <pre><code>private void Canvas_MouseDown_1(object sender, System.Windows.Input.MouseButtonEventArgs e)
  {
      // Console.WriteLine("Clicked");
       if (e.ButtonState == MouseButtonState.Pressed)
        {
            offset = e.GetPosition(sender as FrameworkElement);
            Console.WriteLine("Offset: " + offset.ToString());
            currentPoint = e.GetPosition(this);
        }
  }
  
  private void Canvas_MouseMove_1(object sender, System.Windows.Input.MouseEventArgs e)
  {
        if (e.LeftButton == MouseButtonState.Pressed)
        {
              Line line = new Line();
              line.Stroke = SystemColors.WindowFrameBrush;
              line.X1 = currentPoint.X;
              line.Y1 = currentPoint.Y;
              line.X2 = e.GetPosition(this).X;
              line.Y2 = e.GetPosition(this).Y;
  
              currentPoint = e.GetPosition(this);
  
              canvas.Children.Add(line);
        }
  }
  </code></pre>
  
  <p>Is there a way to directly get the point in the canvas element rather than the program window as a whole?  If not, I could get the draw-width and draw-height of the menu elements, but that doesn't seem like the most elegant solution.</p>
  
  <p>Thanks!</p>