The DeviceDisplay class is available at Xamarin.Essentials API. It provides information about the device's screen metrics the application is running on. Android, iOS, and UWP offer unique operating system and platform APIs that developers have access to all in C# leveraging Xamarin. Xamarin.Essentials provide a single cross-platform API that works with any Xamarin.Forms, Android, iOS, or UWP application that can be accessed from shared code no matter how the user interface is created.
Reading this article, you can learn Retrieving Device Display Information like device orientation, rotation, width, height, density in Xamarin Forms application using Xamarin Essentials for Android and Universal Windows Platform with XAML and Visual C# in cross-platform application development.
The following important tools are required for developing Xamarin Forms App,
- Windows 10 (Recommended)
- Visual Studio 2017
- Android API 19 or higher and UWP 10.0.16299.0 or higher.
Now, we can discuss step by step app development.
Step 1
Open Visual Studio 2017 -> Start -> New Project-> Select Cross-Platform (under Visual C#-> Mobile App (Xamarin.Forms)-> Give the Suitable Name for your App (XamFormDevDispinfo) ->OK
Step 2
Select the cross-platform template as a Blank APP ->Set Platform as Android and UWP and code sharing strategy as .NET standard, Afterwards, Visual Studio creates 3 projects (Portable, Droid, UWP)
Step 3
For adding a reference,
RightClick your solution (XamFormDevDispinfo) and Select Manage NuGet Packages.
For adding Xamarin.Essentials Reference, choose browse and search Xamarin.Essentials, select the package and select all the projects (portable, Android, UWP) and install it.
Step 4
Add the Label controls in Mainpage.Xaml for displaying Title and Device orientation, rotation, width, height, density.
- <Label FontAttributes="Bold" Text="Retrieving Device Display info in Xamarin Forms application using Xamarin Essentials for Android and UWP" VerticalOptions="Center" HorizontalOptions="Center"/>
- <Label x:Name="lblOrient" Margin="0,0,0,10" HorizontalTextAlignment="Center"></Label>
- <Label x:Name="lblRot" Margin="0,0,0,10" HorizontalTextAlignment="Center"></Label>
- <Label x:Name="lblWidth" Margin="0,0,0,10" HorizontalTextAlignment="Center"></Label>
- <Label x:Name="lblHeight" Margin="0,0,0,10" HorizontalTextAlignment="Center"></Label>
- <Label x:Name="lblDens" Margin="0,0,0,10" HorizontalTextAlignment="Center"></Label>
Step 5
Add the following code in the MainActivity.cs in XamFormDevDispinfo.Android project,


Vignesh ManiPosted Nov 1, 2018, 1:07 PM
Nice one Sir.