【发布时间】:2012-05-14 17:58:43
【问题描述】:
有没有办法获得 ViewBox 在 XAML Windows 8 Metro Style App 中缩放其内容的比例因子
【问题讨论】:
标签: xaml windows-8 windows-runtime viewbox winrt-xaml
有没有办法获得 ViewBox 在 XAML Windows 8 Metro Style App 中缩放其内容的比例因子
【问题讨论】:
标签: xaml windows-8 windows-runtime viewbox winrt-xaml
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 是一样的,但有高度。
【讨论】:
您可以尝试在其中添加一个网格视图,并自定义其从布局属性到您的内容的列和行。将其宽度和高度设置为自动,并让它拉伸宽度和高度。此外,您应该让您的内容拉伸或再次将 witdh 和高度设置为自动。
另外,你可以尝试体验一下blend tool...
【讨论】:
您可以将其ActualWidth/ActualHeight 与其子级的ActualWidth/ActualHeight 进行比较。请注意,如果将其 Stretch 设置为 Fill,这些可能会有所不同。
【讨论】: