ZoomContentControl : ZoomToRegion by code

Navigation for WPF Forum

Posted 13 years ago by ylchung - OpenSG.NET Corp
Avatar
Hi,

Is there any way zoom in region by code?

I know we have StartZoomToRegion() but it needs user interaction,

I need a method like a "ZoomToRegion(rect r)" so thar I can pass a rect(region).

Or do I have to combine ZoomLeve property and Pan() method?

Could you please show me a sample if it's passible?

Thanks in advance.

[Modified at 07/10/2011 01:11 AM]

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

You would have to set the CenterPoint and ZoomLevel properties, as shown below.
this.zoomContentControl.BeginUpdate();
try {
    this.zoomContentControl.CenterPoint = /* Calculate and set center point */;
    this.zoomContentControl.ZoomLevel = /* Calculate and set zoom level */;
}
finally {
    this.zoomContentControl.EndUpdate();
}
The zoom level calculation would probably be something like the following, but you may need to tweak it:
// Calculate the ideal zoom level, both horizontally and vertically
double zoomLevelX = (width != 0) ? this.zoomContentControl.ViewportSize.Width / width : 0.0;
double zoomLevelY = (height != 0) ? this.zoomContentControl.ViewportSize.Height / height : 0.0;
double zoomLevel = Math.Min(zoomLevelX, zoomLevelY);


Actipro Software Support

Posted 13 years ago by ylchung - OpenSG.NET Corp
Avatar
Thanks, it works great!

I applied your sample code and works great~!

Thanks again!!

[Modified at 07/14/2011 10:10 PM]
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.