Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to detect that a UWP app is running on a small-screen device (phone)

Having read about this, I feel there is still an un-answered question about detecting whether a UWP app is running on a device where it would be appropriate to display in portrait only.

The optimal page layouts for our UWP app are such that on a phone, it's best that we disable landscape mode (we don't need such a restriction for larger format devices). What would be the best-practice approach to accomplish this?

like image 471
Carl R. Avatar asked Oct 13 '15 15:10

Carl R.


People also ask

Is UWP a framework?

UWP XAML framework – this is the part of Windows 10/11 that you use to build your UWP apps with, it contains XAML and the visual layer that is necessary to render your app, including user input functionality. UWP XAML controls – the controls that you use in your UWP apps, they're also part of Windows 10/11.

What is UWP in .NET core?

NET Core. UWP is also known as Windows 10 UWP application. This application does not run on previous versions of Windows but will only run on future version of Windows. Following are a few exceptions where UWP will run smoothly.


2 Answers

You can detect the device family using AnalyticsInfo.VersionInfo.DeviceFamily.

if(AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") {
    // It's a phone
}
else {
    // It's not a phone
}
like image 85
yadejo Avatar answered Nov 14 '22 21:11

yadejo


 if ((Window.Current.Bounds.Width < 640) && (Window.Current.Bounds.Height < 550))
                {
                          //Do something
                }

Best of luck .

like image 45
user2243952 Avatar answered Nov 14 '22 23:11

user2243952