6

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?

Community
  • 1
  • 1
Carl R.
  • 113
  • 5

4 Answers4

17

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
}
yadejo
  • 1,910
  • 15
  • 26
1
 if ((Window.Current.Bounds.Width < 640) && (Window.Current.Bounds.Height < 550))
                {
                          //Do something
                }

Best of luck .

user2243952
  • 277
  • 3
  • 6
  • 12
1

You can also test with hardware buttons availability , 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;
            }
        }
user2243952
  • 277
  • 3
  • 6
  • 12
0

You can check for the hardware back button. Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")

Ken Tucker
  • 4,126
  • 1
  • 18
  • 24