xamarin.forms-旋转隐藏组件

时间:2018-07-09 19:34:35

标签: xamarin.forms orientation

在Xamarin.Forms中,当旋转手机时,我想隐藏某些XAML组件。我似乎找不到简单易用的xamarin提供的任何东西...有人可以向我指出正确的方向吗?

谢谢

1 个答案:

答案 0 :(得分:1)

在Xamarin.Forms Page中,您可以订阅SizeChanged事件或重写OnSizeAllocated方法。有一些不错的documentation描述了这两种选择。以下是使用OnSizeAllocated的示例:

private double width = 0;
private double height = 0;

protected override void OnSizeAllocated(double width, double height)
{
    base.OnSizeAllocated(width, height); //must be called

    if (this.width != width || this.height != height)
    {
        this.width = width;
        this.height = height;

        if (this.width > this.height) 
        {
            // reconfigure for landscape
        }
        else
        {
            // reconfigure for portrait
        }
    }
}