Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
355
Capturing zoom and pan events
posted

Is there a way to capture the user interaction of manually zooming the diagram?  In particular, I want to know if the MouseWheel was used to initiate the zooming of the diagram.  If I put code in the MouseWheel event on my diagram, it doesn't seem to be triggered, so I was wondering if there was another way?  I also tried the NodeResized event and it also does not seem to be triggered by the zoom action.

Similar question as above, but for the manual panning action.  How do I capture whether or not the user is panning the diagram?

Parents
No Data
Reply
  • 34810
    Verified Answer
    Offline posted

    Hello Ken,

    Thank you for your post.

    When a user zooms or pans the XamDiagram there is a property named WindowRect on it that gets changed. As you may have guessed, the WindowRect property returns a Rect object, which has an X, Y, Width, and Height value. When you Zoom the XamDiagram, all of these properties get changed, but when you pan it, only the X and/or Y values get changed. The reason that the NodeResized event is not firing is because the nodes aren't really being resized, it is the WindowRect that is being resized.

    I would recommend that you start by handling the Loaded event on the XamDiagram and have two global Rect objects for the following. In the Loaded event, cast the sender to a XamDiagram and hook up a PropertyChanged event to it. Also in the Loaded event, you should set the two Rect objects to MyXamDiagram.WindowRect. In the PropertyChanged event handler, check for e.PropertyName == "WindowRect." If this is true, set one of the Rect objects to MyXamDiagram.WindowRect, and compare its X, Y, Height, and Width values with the other one because now you have what the WindowRect was before, and what it is currently. After comparing, set the other WindowRect to MyXamDiagram.WindowRect so you can continue to compare them whenever this fires.

    To handle the MouseWheel event, I would recommend hooking into the XamDiagram's PreviewMouseWheel event. To tell if the zoom came from the mouse wheel, you could use a global bool variable and set it in this PreviewMouseWheel event. Then, you can add that to the comparing logic in the PropertyChanged WindowRect checks.

    I have attached a sample application to demonstrate the above.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Developer Support Engineer I
    Infragistics Inc.
    www.infragistics.com/support

    XamDiagramZoomPanCase.zip
Children