有没有办法获得ViewBox在XAML Windows 8 Metro Style App中缩放其内容的比例因子
答案 0 :(得分:3)
WinRTXAMLToolit有一个扩展名。
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
是相同的,但有高度。
答案 1 :(得分:0)
您可以将其ActualWidth/ActualHeight
与其子级的ActualWidth/ActualHeight
进行比较。请注意,如果Stretch设置为Fill
,则这些可能会有所不同。
答案 2 :(得分:0)
您可以尝试在其中添加网格视图,并从布局属性到您的内容自定义其列和行。将它的宽度和高度设置为自动,并让它拉伸宽度和高度。此外,您应该让您的内容拉伸或将witdh和height设置为自动再次自动。
另一方面,您可以尝试体验混合工具......