If you want to stop the event propagation, you could use:
private void CanvasEvent(object sender, RoutedEventArgs e)
{
// Draw/Move stuff
...
e.Handled = true;
}
in your event handlers. Another approach is to disable
the Button
or only add it, when it is used. A third approach could be to add a bool
flag e.g. isDrawing
and in your Button
event handler you check the flag.
private void CanvasEvent(object sender, RoutedEventArgs e)
{
// When drawing etc. starts, where the button should not handle the events
isDrawing = true;
}
private void ButtonEvent(object sender, RoutedEventArgs e)
{
if (isDrawing) { return; }
// When not drawing do stuff
...
}
I would prefer the e.Handled = true;
approach.
It is necessary to set the Background
for the Canvas
explicite otherwise it is not hit-testable (see: WPF: Canvas Events Not working).