How to measure size of content once scaled to fit the zoombox?
#1
I have been looking through the properties and methods you have available, but I am not sure there is one that gives me a way to measure my content once its scaled to fit. I was trying ActualContentBounds but its results are a little confusing. For example I have content that is 5423x2822 unscaled. ActualContentBounds is returning 1625x1149 which is not proportional to the starting size. If there is no way to get the scaled size, is there a way to get the to scale factor used to size the content down to fit the zoom panel? I could at least use that to calculate it.
#2
This is strange.

I have tested that again and the ActualContentBounds worked correctly - with preserving the proportions.

Could you please check that with the ZoomPanelDump sample - here you can replace the tiger.xaml with some bigger content for example palazz_sport.xaml and see how the ActualContentBounds is changing.

If are changing the content from code or otherwise have dynamic content than you can try to call Refresh method on ZoomPanel to recalculate the values of the properties.

You can also check that you are not using RenderTransform on your content - that does not affect measure step and therefore ZoomPanel can get wrong size measurement for its content.

You can also check that your content is really 5423x2822 in size - call Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)) on the object and check its DesiredSize - is it 5423x2822?

Hopefully any advice will help you.
Andrej Benedik
#3
I think this may be a timing issue. I am using an SvgViewbox within a ZoomPanel to load the content from an svg file. I am trying to detect the size of the content in the SvgFileLoaded event of the SvgViewbox but on first load the ActualContentBounds is coming up empty. I tested this before and after I call refresh. Does this only work once a layout pass has occurred by wpf? The size i got before may actually have been from the previous content that was loaded from what I can tell since I load several different svg files that are different sizes. The sample project I sent you has the actual content I am working with.

Maybe I am going about this the wrong way. What I am trying to accomplish is setting the zoom of the zoompanel so that the content fits the window when its rotated 90 degrees left or right. When content is not rotated, the zoompanel sizes it for me automatically. I was taking the approach of loading the content without rotation, measure the content once its scaled to fit, then doing the calculation of its rotated size to figure out how much to zoom in or out to fit the window. Do you have a better way to approach this?
#4
Maybe you can try to use LayoutTransform to rotate your content.

To give you more control over the process I would load the svg file in code with Ab2d.ReaderSvg class (instead of SvgViewbox). After reading the svg file you will get a Viewbox with read objects.

Because Viewbox has its own layout management, it is recommended to get its child (Canvas) and use for the ZoomPanel's child. Before changing the parent of the Canvas, you need to disconnect it from Viewbox first.

Than add LayoutTransform with rotate transform.

Code:
Viewbox svgViewbox = Ab2d.ReaderSvg.Instance.Read(svgFileName);
Canvas svgRootCanvas = svgViewbox.Child as Canvas;
svgViewbox.Child = null; // disconnect canvas

svgRootCanvas.LayoutTransform = new RotateTransform(90);

ZoomPanel1.Content = svgRootCanvas;
ZoomPanel1.Refresh();
Andrej Benedik
#5
Still no luck. I tried what you suggested, but I lose my viewbox if I do. I have only a portion of my svg content visible, and the svgviewbox allows me to only show the area defined by the viewbox. By doing it this way, everything is visible. Also I found that when I apply a rotation to it, i cant seem to find the center point of elements that are clicked so I can zoom to them. I am going to send you a sample project so you can see what is happening.
#6
Did you receive my sample project?
  


Forum Jump:


Users browsing this thread:
1 Guest(s)