-2

我已经在我的机器上安装了芒果SDK,我想创建一个在Windows Phone OS 7.0和Windows Phone OS 7.5设备上运行的应用程序。另外我需要在同一个应用程序中实现许多芒果功能。可能吗 ?如果是,请告诉我如何进行版本检查,因为基于我们需要实现芒果功能的版本。WP7.1向后兼容性

回答

6

你将不得不维护两个不同的版本。您无法同时编译一个支持两个版本的XAP。

Mango API仅在使用7.1 SDK编译时才可用。因此,您不能在代码中进行联机检查。

但是这是毫无意义的,因为几乎没有用户还没有升级到芒果,并且所有新手机都带有芒果。

+1

如果你让为自己的受众特征的应用程序,我完全同意这种说法;这里唯一的问题是与客户合作,说服他们放弃7.0的支持 - 我上次检查时,微软没有发布关于Mango vs 7.0的用户百分比的任何信息。 – 2012-01-04 08:38:22

2

可以使用Type类和反思,虽然过程并不容易做到这一点。创建了Windows Phone 7.0的应用程序,然后创建一个实现了芒果特定功能MangoExtensions类:

http://www.sharpgis.net/post/2011/08/21/Windows-Phone-Adding-Mango-features-to-a-70-WinPhone-App.aspx

bool IsMangoDevice = (Environment.OSVersion.Version >= new Version(7, 1)); 

if (IsMangoDevice) 
{ 
    Type t = Type.GetType("Microsoft.Phone.Shell.StandardTileData, Microsoft.Phone"); 

    //get the constructor for the StandardTileData and create a new instance of it 
    var newTileData = t.GetConstructor(new Type[] { }).Invoke(null); 
    //Get the setter method for the title property 
    var setMethod = newTileData.GetType().GetProperty("Title").GetSetMethod(); 
    //Set the tile title 
    setMethod.Invoke(newTileData, new object[] { "This is my new tile" }); 
    //Get the create method for the shell tiles 
    Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone"); 
    var createMethod = shellTileType.GetMethod("Create"); 
    //Create the tile, with the uri and tile data 
    Uri uri = new new Uri("/MainPage.xaml?Test=This_Came_From_A_Secondary_Tile", UriKind.Relative) 
    createMethod.Invoke(null, new object[] { uri, newTileData}); 
}