Calculate ViewBox ScaleFactor on a Metro Style App

痞子三分冷 提交于 2019-12-02 04:38:47

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

Filip Skakun

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.

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