Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Disable Diagram.MouseWheel to cause the view to scroll. (Read 2025 times)
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Disable Diagram.MouseWheel to cause the view to scroll.
Apr 9th, 2020 at 4:14pm
Print Post  
Hi All,

Today I conducted a series of tests on Diagram.

I currently set Diagram.Bounds = "-1000, -1000,2000,2000". ShapeNode.Bounds = "0,0,500,500". I tried to display the ShapeNode as soon as the Diagram was loaded, so I put Diagram. ZoomToRect (ShapeNode.Bounds, true); written in Diagram.Loaded event. Then the scaling value of Diagram is restricted in Diagram.MouseWheel event. I have tried when the zoom value of Diagram reaches the limit value, if continue to zoom, the view will scroll.

I want to prohibit the view from scrolling. The Diagram.MouseWheel event only allows zoom operations on the ShapeNode, and the zoom must be performed at the center of the view.

Any assistance would be appreciated.

Cheers,

Jack
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Disable Diagram.MouseWheel to cause the view to scroll.
Reply #1 - Apr 10th, 2020 at 5:17am
Print Post  
Hello,

What is the current zoom code that you are using? To make the viewport not shift after zoom, you need to make sure its center point remains the same before and after zooming.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Disable Diagram.MouseWheel to cause the view to scroll.
Reply #2 - Apr 10th, 2020 at 8:07am
Print Post  
Hello,

The zoom code I currently use is as follows:
private void diagram_MouseWheel (object sender, MouseWheelEventArgs e)
        {
            var imageBounds = imageNode.Bounds;
            var zoomRect = diagram.Viewport;
            var zoomStep = 10;

            if (e.Delta <0)
            {
                zoomRect = new Rect
                (
                    Math.Max ​​(imageBounds.X, zoomRect.X-zoomStep / 2),
                    Math.Max ​​(imageBounds.Y, zoomRect.Y-zoomStep / 2),
                    Math.Min (imageBounds.Width, zoomRect.Width + zoomStep),
                    Math.Min (imageBounds.Height, zoomRect.Height + zoomStep)
                );
            }
            else
            {
                zoomRect = new Rect
                (
                    Math.Min (overlayNode.Bounds.X, zoomRect.X + zoomStep / 2),
                    Math.Min (overlayNode.Bounds.Y, zoomRect.Y + zoomStep / 2),
                    Math.Max ​​(10, zoomRect.Width-zoomStep),
                    Math.Max ​​(10, zoomRect.Height-zoomStep)
                );
            }
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Disable Diagram.MouseWheel to cause the view to scroll.
Reply #3 - Apr 10th, 2020 at 9:00am
Print Post  
Hello,

Code
Select All
private void diagram_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
	var zoomInMax = overlayNode.Bounds; // The bigger node in your example, replace/inflate if needed by your requirements
	var zoomOutMax = imageNode.Bounds; // The smaller node in your example, replace/inflate if needed by your requirements
	var zoomRect = diagram.Viewport;
	var zoomStep = 10;

	double width, height;
	if (e.Delta < 0)
	{
		width = Math.Min(zoomOutMax.Width, zoomRect.Width + zoomStep);
		height = Math.Min(zoomOutMax.Height, zoomRect.Height + zoomStep);
	}
	else
	{
		width = Math.Max(zoomInMax.Width, zoomRect.Width - zoomStep);
		height = Math.Max(zoomInMax.Height, zoomRect.Height - zoomStep);
	}

	var dw = width - zoomRect.Width;
	var dh = height - zoomRect.Height;
	zoomRect = new Rect(zoomRect.X - dw / 2, zoomRect.Y - dh / 2, width, height);

	diagram.ZoomToRect(zoomRect, true);

	// stop the scrollviewer from scrolling
	e.Handled = true;
} 



The above code will carry out a zoom operation with outer limit set to the zoomOutMax variable and inner limit set to the zoomInMax variable. It should remain centered always to the current viewport of the diagram. You can increase/decrease the sizes of the limits as per your requirements.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Disable Diagram.MouseWheel to cause the view to scroll.
Reply #4 - Apr 10th, 2020 at 9:50am
Print Post  
Smiley Smiley Smiley Smiley Smiley
Thank you very much.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint