Calculate ViewBox ScaleFactor on a Metro Style App

岁酱吖の 提交于 2019-12-02 08:41:32

问题


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


回答1:


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.




回答2:


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...




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!