tags:

views:

247

answers:

0

In a simple code-only WPF application I'm writing, I would like to have a custom Canvas.

I've found questions similar to this one here in StackOverflow, but couldn't find exactly this one, nor a simple way to adapt another answer to my specific problem (please note that I have not much experience in WPF).

In my canvas, I'd like it to have the following properties:

  1. the point (0, 0) is on the center of the Canvas;
  2. the x-axis points to the right;
  3. the y-axis points to the top;
  4. the point (1, 0) is about 1 inch to the right of the origin; and
  5. in every event, the position of the mouse is given in the coordinate system defined above.

In this answer, Ray Burns propose a very simple solution to my first 3 points. It is trivial to modify that code so that it deals with my point number 4 as well (change 1 and -1 in the RenderTransform to other constants).

However, that very simple and excellent solution for many problems is based on setting width and height to 0, and centering the canvas on its container. Therefore, there's no canvas to capture events like a click, so this solution won't handle my fifth property.

What's the easiest way to achieve this? Inherit from Panel and do everything by hand? Inherit from Canvas, intercept every event and modify the coordinates?