Nikita Goncharuk
Nikita Goncharuk

Reputation: 815

Get Screen Width in dpi Xamarin.Forms

I need to get a screen size in dpi. I've seen a way to use the XLabs library, can I do without it

Upvotes: 2

Views: 1843

Answers (1)

Mauro Piccotti
Mauro Piccotti

Reputation: 1847

In Forms I think that you can do only this:

App.AppContext.ScreenSize.Width
App.AppContext.ScreenSize.Height

But you can obviously create a custom renderer, and in Android you have also these properties:

Context.Resources.DisplayMetrics.Xdpi
Context.Resources.DisplayMetrics.Ydpi

While in iOS these:

UIScreen.MainScreen.Bounds.Width
UIScreen.MainScreen.Bounds.Height

For UWP these:

var display = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
double xDpi = display.RawDpiX;
double yDpi = display.RawDpiY;

Upvotes: 3

Related Questions