Context:
There's an application where you draw things on canvas. Where user clicks there's a black dot, for example. But handling that events raised by canvas in event handlers in main window code is just ugly for me. So I wrote a class which methods mirror canvas mouse events and I call those methods inside event handler.
public partial class Window1 : Window
{
DrawingTool drawTool = new DrawingTool();
public Window1()
{
InitializeComponent();
}
private void drawingCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
drawTool.OnMouseLeftButtonDown(e);
}
}
Nice, but I want more...
Question:
Is it possible to handle events raised by canvas in my DrawingTool class directly without having defined canvas event handlers. I'd like to keep my Window1 code clean and focused on window stuff and move events handling completely into my classes.
I thought about deriving DrawingTool from FrameworkElement, override OnRender and draw it transparently over the canvas so user's click seemed to be made on canvas but in fact would be raised in DrawingTool and handled internally. This approach works with drawing functionality (after drawing is done drawn object is added to canvas children and removed from DrawingTool children) but when it comes to selection mode or others there are problems with hit testing of elements for example.
So, I'll be grateful for any suggestion how to solve my problem or explanation why this is a stupid idea at all :)