See this question: Get the size (after it has been "stretched") of the element in the ViewBox
Basically, if you have a Viewbox named viewbox, you can get a ScaleTransform as follows
ContainerVisual child = VisualTreeHelper.GetChild(viewbox, 0) as ContainerVisual; ScaleTransform scale = child.Transform as ScaleTransform;
You can also create an extension method for the Viewbox , which you can name as follows
viewbox.GetScaleFactor();
ViewBoxExtensions
public static class ViewBoxExtensions { public static double GetScaleFactor(this Viewbox viewbox) { if (viewbox.Child == null || (viewbox.Child is FrameworkElement) == false) { return double.NaN; } FrameworkElement child = viewbox.Child as FrameworkElement; return viewbox.ActualWidth / child.ActualWidth; } }
Fredrik hedblad
source share