1
votes

I have a canvas control in my WPF project:

<Canvas x:Name="mainCanvas" Margin="0" 
        MouseMove="mainCanvas_MouseMove"     
        MouseLeftButtonDown="mainCanvas_MouseLeftButtonDown"/>

In this canvas control, there are some other Canvas controls as children.

The problem is that when I click on these child canvas controls, the mainCanvas_MouseLeftButtonDown callback is not called. I don't bind anything to the mouse down event of these child canvases.

The mainCanvas_MouseMove callback seems to be working fine though, it is called even when I mouse over the child canvases.

I tried preview mouse down events with no luck.

How can I solve this problem?

1
Post your children canvas Xaml - makc
It is dynamically created. Here it is: pastebin.com/aeUgDans - Canol Gökel
<Canvas Background="Transparent"> to get mouse events and set <ScrollViewer Focusable="False"> if the canvas is inside a scroll viewer - r2d2

1 Answers

0
votes

the events aren't bubbling up because someone on the visual tree has handled them.

you should use snoop to see who handled the events

otherwise just register the children canvases to the eventHandlers

public override Canvas CreateCanvas()
{
  Canvas canvas = new Canvas();

  canvas.MouseMove +=new MouseEventHandler(mainCanvas_MouseMove);
  canvas .MouseLeftButtonDown +=new MouseButtonEventHandler(mainCanvas_MouseLeftButtonDown);

 // your code here
}

when you destroy your children canvases don't forget to unregister the events.