xamarin.forms - 旋转时隐藏组件

xamarin.forms - hide components on rotation

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

谢谢

在 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
        }
    }
}