Left mouse button while using ViewboxLimited
#1
I have a situation where I use the left mouse button to select items on a canvas. The items can be very small so I also need zoom capabilities. The ViewboxLimited solution gives the perfect zoom capabilities but when when I select ZoomMode="Move" (or others), the MouseButtonLeftUp event no longer gets triggered so my selection no longer functions. I don't need the ability to move the canvas as the wheel gives all the control I need.

Do you have a suggestion?

Thanks again for all you do Andrej and for a great product.
#2
ZoomPanel also subscribes to MouseButtonLeftUp event and in case it is set to Move mode (or some other mode except None), it handles the event. This means that you will not get it.

But you can be notified about mouse event before ZoomPanel if you use PreviewMouse... events. In case of using Preview events, you need to set the Handled property of the MouseButtonEventArgs (get as parameter into event handler) to true in case when you handled the event by yourself - this means that the mouse down, up or some other event was used by your code and should not be used by some other subscriber - in this case ZoomPanel. This way, you can control which mouse down and up events are passed through ZoomPanel - those that are not handled by your code.

For example (taken from updates "ZoomToObjectSample"):
Code:
// Subscribe to events:
var newShape = new Rectangle();
newShape.PreviewMouseLeftButtonDown += NewShape_MouseLeftButtonDown;
newShape.PreviewMouseLeftButtonUp += NewShape_MouseLeftButtonUp;

// Event handlers:
private void NewShape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    // Because this event handler is subscribed to our shape, we should handle this event so it does not get passed on to ZoomPanel (we do not want that two actions occur on one mouse event)
    e.Handled = true;
}

void NewShape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
     // Add code to handle the object selection on mouse click here
     // ...

    // Because this event handler is subscribed to our shape, we should handle this event so it does not get passed on to ZoomPanel (we do not want that two actions occur on one mouse event)
    e.Handled = true;
}
Andrej Benedik
#3
Worked perfectly.

Thanks Andrej!
  


Forum Jump:


Users browsing this thread:
1 Guest(s)