Xamarin.Essentials: Device Display Information

Pre-release NuGet

The DeviceDisplay class provides information about the device's screen metrics the application is running on.

Using DeviceDisplay

Add a reference to Xamarin.Essentials in your class:

using Xamarin.Essentials;

Screen Metrics

In addition to basic device information the DeviceDisplay class contains information about the device's screen and orientation.

// 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;

The DeviceDisplay class also exposes an event that can be subscribed to that is triggered whenever any screen metric changes:

public class ScreenMetricsTest
    public ScreenMetricsTest()
        // Subscribe to changes of screen metrics
        DeviceDisplay.ScreenMetricsChanged += OnScreenMetricsChanged;

    void OnScreenMetricsChanged(ScreenMetricsChangedEventArgs  e)
        // Process changes
        var metrics = e.Metrics;