I'm trying to get the size (width/height) of an Image
control after I applied a Transform
to it (either Render- or Layouttransform, doesn't matter in this case).
My Image
control is embedded in a ScrollViewer
. I'm using the Layout/Rendertransform to zoom the image which does work, but the ActualWidth/ActualHeight or RenderSize properties don't show me the new height/width. I tried calling InvalidateMeasure()
and UpdateLayout()
on the Image control without success.
This is my current code to zoom the image to the height:
double imageHeight = imageBox.ActualHeight;
double containerHeight = (imageBox.Parent as ScrollViewer).ActualHeight;
double facHeight = containerHeight / imageHeight;
var scaleTransform = imageBox.LayoutTransform.Value; //imageBox.RenderTransform.Value;
scaleTransform.ScalePrepend(facHeight, facHeight);
MatrixTransform newTransform = new MatrixTransform(scaleTransform);
imageBox.LayoutTransform = newTransform;
On first execution of that method the image will be (more or less) correctly zoomed. In this case, I want the image vertically fully shown, regardless of it's width, so that I only have a horizontal scrollbar (or no scrollbar at all if imageHeight > imageWidth).
On second execution, it'll zoom in again because imageBox.ActualHeight
didn't change.
I tried various combinations of InvalidateMeasure and UpdateLayout but that didn't help.