【问题标题】:xamarin.forms - hide components on rotationxamarin.forms - 旋转时隐藏组件
【发布时间】:2018-12-17 13:39:28
【问题描述】:

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

谢谢

【问题讨论】:

    标签: xamarin.forms orientation


    【解决方案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
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-20
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2010-11-12
      相关资源
      最近更新 更多