The correct way to detect that the UWP application is running on a device with a small screen (phone)

After reading this , I feel that there is still an unresolved question of whether the UWP application is working on a device where it would be advisable to display only on a portrait.

The optimal page layouts for our UWP application are such that it’s best to turn off landscape mode on your phone (we don’t need such a restriction for larger devices). What would be the best approach to achieve this?

+4
source share
4 answers

You can define a device family using AnalyticsInfo.VersionInfo.DeviceFamily.

if(AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") {
    // It a phone
}
else {
    // It not a phone
}
+9
 if ((Window.Current.Bounds.Width < 640) && (Window.Current.Bounds.Height < 550))
                {
                          //Do something
                }

.

+1

You can also check for hardware buttons, but not every phone has them!

public  Platform DetectPlatform()
        {
            bool isHardwareButtonsAPIPresent = ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");

            if (isHardwareButtonsAPIPresent)
            {
                return Platform.WindowsPhone;
            }
            else
            {
                return Platform.Windows;
            }
        }
+1
source

You can check the equipment return button. Windows.Foundation.Metadata.ApiInformation.IsTypePresent ("Windows.Phone.UI.Input.HardwareButtons")

0
source

Source: https://habr.com/ru/post/1611457/


All Articles