Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to reference ContentPages inside OnSizeAllocated on a MasterDetailPage Master?

$
0
0

Anyone know a way to reference the ContentPage in the MasterDetailPage.Master inside OnSizeAllocated on a MasterDetailPage? I need the background image to scale properly and defining it on the ContentPage itself won't work since Xamarin doesn't scale them properly for the iPhone 6 etc.

Here is my code that I use on the other pages:

protected override void OnSizeAllocated (double width, double height)
{
    base.OnSizeAllocated (width, height);

    // iPhone 4 320 x 480
    // iPhone 5 320 x 568
    // iPhone 6 375 
    // iPhone 6 Plus 414

    if (width >= 414)
        // iPhone 6 Plus
        this.BackgroundImage = "backgrounds/bg_login-736h@3x.png";
    else if (width >= 375)
        // iPhone 6
        this.BackgroundImage = "backgrounds/bg_login-667h@2x.png";
    else if (width >= 320 && height >= 568)
        // iPhone 5
        this.BackgroundImage = "backgrounds/bg_login-568h@2x.png";
    else if (width >= 320)
        // iPhone 4
        this.BackgroundImage = "backgrounds/bg_login@2x.png";
    else
        this.BackgroundImage = "backgrounds/bg_login.png";

}

Viewing all articles
Browse latest Browse all 58056

Trending Articles