I prefer to do by code, here is my solution:
My App.xaml app always has my device screen:
public static double ScreenWidth { get; set; } public static double ScreenHeight { get; set; }
Then on my main Android OS:
Passapp.App.ScreenWidth = (double)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density); Passapp.App.ScreenHeight = (double)(Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);
And in my iOS AppDelegate:
App.ScreenWidth = UIScreen.MainScreen.Bounds.Width; App.ScreenHeight = UIScreen.MainScreen.Bounds.Height;
So, when you have the width and height of the screen, you can do this on any page:
public partial class MyPage : ContentPage { public MyPage() { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); var layout = new AbsoluteLayout(); #if __ANDROID__ BackgroundImage = "Background"; #endif #if __IOS__ Image img = new Image() { Source = "Background", Aspect = Aspect.Fill }; layout.Children.Add(img, new Rectangle(0, 0, App.ScreenWidth, App.ScreenHeight)); #endif Content = layout; } }
source share