Detect OS version - Windows Phone 7 or Windows Pho

2019-01-25 10:16发布

问题:

I have an application for Windows Phone 7. I have created visual studio 2012 in windows 8 desktop. I am trying to use the application in Windows Phone 8 device also with some changes involved. How can I programmatically detect whether the device is Windows Phone 7 or Windows Phone 8?

回答1:

Just as you would on any other platform with C#: Environment.OSVersion



回答2:

You can use this toolkit to check the version of the phone: http://mangopollo.codeplex.com/

bool IsWP8() : Returns if the phone running the application is a Windows Phone 8

EDIT: If you don't want to use the whole toolkit here is how it checks it:

public static bool IsWP8 { get { return Environment.OSVersion.Version >= TargetedVersion; } }

    private static Version TargetedVersion = new Version(8, 0);

Creds to original author.



回答3:

You shouldn't need to.

Either it is a Windows Phone 7 app and will work on both Windows Phone 7 and Windows Phone 8 devices or it is a Windows Phone 8 application.

A Windows Phone 7 app running on Windows Phone 8 shouldn't be able to do anything that a Windows Phone 7 device shouldn't be able to do.



回答4:

This article has some good strategies as well.

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202996(v=vs.105).aspx

It is not just about run-time either, for example, your code may function one way on wp7 and another on wp8 depending on availability of an API. In this case a #define may the best way to go, because you really don't care what kind of device you are running on, but what SDK you were built against.