在 Metro Style 应用程序上计算 ViewBox ScaleFactor [英] Calculate ViewBox ScaleFactor on a Metro Style App

查看:32
本文介绍了在 Metro Style 应用程序上计算 ViewBox ScaleFactor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获得 ViewBox 在 XAML Windows 8 Metro Style App 中缩放其内容的比例因子

Is there any way to get the scale factor by which a ViewBox scales its content in a XAML Windows 8 Metro Style App

推荐答案

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 是一样的,但是有高度.

GetChildScaleY is the same, but with Heights.

这篇关于在 Metro Style 应用程序上计算 ViewBox ScaleFactor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆