Cant capture MouseUp of left button on childen of zoom panel
No matter how I declare the handler for the MouseUp event on children within the zoompanel, the event never fires. It does on right mouse button and if I remove the zoompanel from around it. I even went as far as attaching to the event manually using AddHandler and using the "handledEventsToo" option. Any thoughts on why this is happenning?
To elaborate just a bit more, I have a zoompanel with a canvas inside it. The canvas is loaded with content dynamically at runtime that want to capture all mouseup events from every child. The canvas itself is not being clicked. When I add the handler to the canvas, it never fires. The content within the canvas should be firing the event, and they do when they are not within the zoompanel. They bubble up to the canvas as they should in that case. What is the zoompanel doing that would prevent this from working?
When ZoomPanel is active, it captures the mouse events to handle zooming and panning.

To get left button events you need to deactivate the ZoomPanel by setting its ZoomMode to None. If you are using ZoomController this mode is set when the current mode is deactivated - for example if currently move mode is activated (the first button) than the ZoomMode is set to None when the user clicks again on Move button.

To see more details about how to do this please see the PainterSample that comes with ZoomPanel - it is using mouse events on the Canvas inside ZoomPanel to draw on the canvas with the mouse.

If you do not want to put the ZoomPanel's ZoomMode to None, you can subscribe to PreviewMouseLeftButtonDown, PreviewMouseLeftButtonUp, etc. events and get the events before ZoomPanel will get them. In the handler you can can decide if you want to process the event by yourself or pass it to ZoomPanel. If you handle the event by yourself, than set the e.Handled in the EventArgs to true to prevent passing the event further to ZoomPanel.

A similar approach (using Preview mouse events) is used in the Multi mouse buttons sample that comes with ZoomPanel.

When ZoomMode on ZoomPanel is not set to None
Andrej Benedik
I dont want to have to turn off the zoommode because I still need to be able to pan. If I attach a preview event handler to the container around the zoompanel or the zoompanel iteself, the event does not tell me which item was actually clicked. Its always the zoompanel. If I attach handlers directly to the items within the zoompanel, they never fire.

Is there a possibility of allowing these events to bubble instead of cancelling them? Maybe add your own implementation of them?
I do not know why the events for the objects inside ZoomPanel do not fire. I created simple test with PainterSamle and I can get the events fire - see the following code:

void PainterSample_Loaded(object sender, RoutedEventArgs e)
            // Set the content to be a litte bit smaller than the height of the ZoomPanel
            SetNewContent(null, new Size(ZoomPanel1.ActualHeight * 0.7, ZoomPanel1.ActualHeight - 30));

            Ellipse ellipse = new Ellipse();
            ellipse.Width = 200;
            ellipse.Height = 100;
            ellipse.Fill = Brushes.Red;
            ellipse.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ellipse_PreviewMouseLeftButtonDown);
            Canvas.SetLeft(ellipse, 50);
            Canvas.SetTop(ellipse, 100);

        void ellipse_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
              // Put breakpoint here

I you would like to put events to ZoomPanel and would like to get the object under the mouse you can use WPF 2D hit testing - see

Another approach would be to put ZoomMode to none. Add the canvas or some other panel as the first child inside ZoomPanel - set its background to some color (can be also Transparent; it it is null than the events will not be fired on the control). Subscribe to mouse left button up and down events on this panel. In the button down you set the ZoomMode to Move and in the button up you set the ZoomMode to None.

Now you can add controls to the panel and subscribe to the events on them and do whatever you want in those event handlers.

This way you would get your events when you click on the controls inside the panel. But if you would click on the root panel (the empty space around your controls) you would start panning.
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)