Is there any way to get the scale factor by which a ViewBox scales its content in a XAML Windows 8 Metro Style App
The WinRTXAMLToolit has an extension for this.
public static double GetChildScaleX(this Viewbox viewbox)
{
if (viewbox.Child == null)
throw new InvalidOperationException("Can't tell effective scale of a Viewbox child for a Viewbox with no child.");
var fe = viewbox.Child as FrameworkElement;
if (fe == null)
throw new InvalidOperationException("Can't tell effective scale of a Viewbox child for a Viewbox with a child that is not a FrameworkElement.");
if (fe.ActualWidth == 0)
throw new InvalidOperationException("Can't tell effective scale of a Viewbox child for a Viewbox with a child that is not laid out.");
return viewbox.ActualWidth / fe.ActualWidth;
}
GetChildScaleY
is the same, but with Heights.
You may try to add a grid view inside it and customize its' columns and rows from layout property up to your content. Set it width and height to auto, and let it stretch width and height. Also you should let your content stretch or set witdh and height to automatic again.
On the other way, you can try to experience blend tool...
You can compare its ActualWidth/ActualHeight
to the ActualWidth/ActualHeight
of its child. Note that these might be different if its Stretch is set to Fill
.
来源:https://stackoverflow.com/questions/10588589/calculate-viewbox-scalefactor-on-a-metro-style-app