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

How to reference ContentPages inside OnSizeAllocated on a CarouselPage?

$
0
0

Anyone know a way to reference the ContentPages inside OnSizeAllocated on a CarouselPage? I have three ContentPages in the CarouselPage that need to all have different background images and simply setting the background image 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



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>