Reputation: 113
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?
Upvotes: 6
Views: 2422
Reputation: 1968
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
}
Upvotes: 17
Reputation: 277
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;
}
}
Upvotes: 1
Reputation: 277
if ((Window.Current.Bounds.Width < 640) && (Window.Current.Bounds.Height < 550))
{
//Do something
}
Best of luck .
Upvotes: 1
Reputation: 4156
You can check for the hardware back button. Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")
Upvotes: 0