1

In my Xamrin.Forms app i used this method for get the screen resolution: I wrote an interface with height and width properties and in the iOS rendere I used UIScreen.MainScreen.Bounds.Height and UIScreen.MainScreen.Bounds.Width. And it was ok... until about one month ago! Now, if I run my app on iPhone 5c (screen resolution declared 1136x640) the values are 568x320 whit scale 2 and if I run it on iPhone 6 (resolution declared 1334x750) the values are the same, 568x320 whit scale 2!

Does anybody know what is changed?

Thanks

R.Catania
  • 21
  • 4
  • 1
    Possible duplicate of [Density of screen in iOS and Universal WIndows App](http://stackoverflow.com/questions/41489532/density-of-screen-in-ios-and-universal-windows-app) – Matthew Regul Jan 06 '17 at 17:13
  • The solution you mentioned is my original solution, but in this moment it doesn't work. Better, it works, but I received the same values for iPhone 5 and iPhone 6 – R.Catania Jan 09 '17 at 07:34

1 Answers1

0

No need to use dependency service to get device width & height.

Best way to get screen width & height, whenever screen height or width changes or screen is rotated OnSizeAllocated() will get fired and you will get new width & height

sample code :

using Xamarin.Forms;

namespace ABC
{
    public class MyPage : ContentPage
    {
        private double _width;
        private double _height;

        public MyPage()
        {
            Content = new Label {
                Text = "Welcome to Xamarin.Forms!"
            };
        }

        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);
            _width = width;
            _height = height;
        }
    }
}
Jay Patel
  • 528
  • 8
  • 26
  • Thanks @JayPatel for your reply, but your seggestion doesn't resolve my problem. On iPhone 5C and on iPhone 6 the method OnSizeAllocated return the same values: 320 x 568 – R.Catania Jan 02 '17 at 09:37