c# - How in Xamarin Forms project use different sizes of BackgroundImage property for Page? -


i've added types of image in resources

 - 320 x 480 login-background.png  - 640 x 960 login-background@2x.png  - 640 x 1136 login-background-568h@2x.png  - 750 x 1334 login-background-667h@2x.png 

solution explorer pic

then i've filled backgroundimage property in xaml "image/login-background" xaml page pic

but still not work. both device andthe simulator render 320 x 480.

xaml not recognize -568h or @2x e.t.c ios. chooses image matches exact name without extension. works in android because images have same name , resolution folders different.

as workaround can set images c# code behind looking @ height/width overriding onsizeallocated method.

protected override void onsizeallocated(double width, double height) {     base.onsizeallocated(width, height);     string backgroundimgname = "myimage";     device.onplatform(ios: () =>     {         if (width >= 414)             // iphone 6 plus             this.backgroundimage = backgroundimgname + "-736h@3x.png";         else if (width >= 375)             // iphone 6             this.backgroundimage = backgroundimgname + "-667h@2x.png";         else if (width >= 320 && height >= 500)             // iphone 5             this.backgroundimage = backgroundimgname + "-568h@2x.png";         else if (width >= 320)             // iphone 4             this.backgroundimage = backgroundimgname + "@2x.png";         else             this.backgroundimage = backgroundimgname + ".png";     },     android: () => { this.backgroundimage = backgroundimgname + ".png"; }     ); } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -