solarissf
solarissf

Reputation: 1277

xamarin.forms - hide components on rotation

In Xamarin.Forms, when the phone is rotated I want to hide certain XAML components. I can't seem to find anything available from xamarin simple to use... can someone point me in the right direction?

thank you

Upvotes: 2

Views: 368

Answers (1)

gannaway
gannaway

Reputation: 1882

Within a Xamarin.Forms Page, you could subscribe to the SizeChanged event or override the OnSizeAllocated method. There is some good documentation that describes both options. Below is an example of using 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
        }
    }
}

Upvotes: 1

Related Questions