Manthiram
Manthiram

Reputation: 171

get width and height of mobile using xamarin forms

I am new to xamarin.forms. I want to get height,width and resolution of my mobile programmatically in xamarin.forms. Please help to resolve this.

Upvotes: 1

Views: 3635

Answers (1)

EvZ
EvZ

Reputation: 12169

Recently Xamarin.Essentials NuGet pakage was released and there is a useful class DeviceDisplay in there that should handle this task for you.

The documentation can be found here.

Usage example:

// Get Metrics
var metrics = DeviceDisplay.ScreenMetrics;

// Orientation (Landscape, Portrait, Square, Unknown)
var orientation = metrics.Orientation;

// Rotation (0, 90, 180, 270)
var rotation = metrics.Rotation;

// Width (in pixels)
var width = metrics.Width;

// Height (in pixels)
var height = metrics.Height;

// Screen density
var density = metrics.Density;

Upvotes: 7

Related Questions