怎么让你的应用在WP7.8系统下也支持大磁贴

 

wp7.8 和wp8 Live Tile的区别在于wp7.8的第三方应用仅支持两种大小的Tile 而wp8支持三种 应为wp8开放了三种模板供开发者使用,

而wp7.8仅有一种模板那就是TileTemplate5,这也是默认的。Tile展示方式。TileTemplate5 只能够使用一种大小,它与 Windows Phone 8 中等大小相对应

 

既然wp7.8支持大磁贴的话 那么 wp8 引用 Microsoft.Phone.Shell 下的三种模板如果通过反射的方式 ,wp7.8肯定也能支持,(WP8三种模板了解 给出链接 http://www.silverlightchina.net/html/zhuantixilie/winphone7/2012/1229/21142.html)

这里通过反编译wp8下的Filp模板。当然也可以反射Cycle和 Icon 只要属性和方法和反射中的一一对应就OK

好了用过代码演示:

1:如果想让你的应用支持大磁贴的话(WP8除外) 就必须判断你手机版本是 7.5还是7.8

新建一个 CheckOSVersion类  // wp7.8的最低版本是8858所以就用8858最低版本来判断

public class CheckOSVersion

{

   private static Version TargetedVersion;

        public static bool IsTargetedVersion        

    {        

     get             {   return Environment.OSVersion.Version >= CheckOSVersion.TargetedVersion;             }    

       }

        static CheckOSVersion()         {             CheckOSVersion.TargetedVersion = new Version(7, 10, 8858);         }

}

 

2: 创建反射shell.dll的方法

 private static void SetProperty(object instance, string name, object value)
        {
            MethodInfo setMethod = instance.GetType().GetProperty(name).GetSetMethod();
            object[] objArray = new object[1];
            objArray[0] = value;
            setMethod.Invoke(instance, objArray);
        }

//属性必须和Filp下的对应的属性一致
        public static void UpdateFlipTile(string title, string backTitle, string backContent, string wideBackContent, int count, Uri tileId, Uri smallBackgroundImage, Uri backgroundImage, Uri backBackgroundImage, Uri wideBackgroundImage, Uri wideBackBackgroundImage)
        {
            if (CheckOSVersion.IsTargetedVersion)
            {
                Type type = Type.GetType("Microsoft.Phone.Shell.FlipTileData, Microsoft.Phone");
                Type type1 = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
                foreach (ShellTile activeTile in ShellTile.ActiveTiles)
                {
                    if (activeTile.NavigationUri.ToString() != tileId.ToString())
                    {
                        continue;
                    }
                    object obj = type.GetConstructor(new Type[0]).Invoke(null);
                    CheckOSVersion.SetProperty(obj, "Title", title);
                    CheckOSVersion.SetProperty(obj, "Count", count);
                    CheckOSVersion.SetProperty(obj, "BackTitle", backTitle);
                    CheckOSVersion.SetProperty(obj, "BackContent", backContent);
                    CheckOSVersion.SetProperty(obj, "SmallBackgroundImage", smallBackgroundImage);
                    CheckOSVersion.SetProperty(obj, "BackgroundImage", backgroundImage);
                    CheckOSVersion.SetProperty(obj, "BackBackgroundImage", backBackgroundImage);
                    CheckOSVersion.SetProperty(obj, "WideBackgroundImage", wideBackgroundImage);
                    CheckOSVersion.SetProperty(obj, "WideBackBackgroundImage", wideBackBackgroundImage);
                    CheckOSVersion.SetProperty(obj, "WideBackContent", wideBackContent);
                    object[] objArray = new object[1];
                    objArray[0] = obj;
                    type1.GetMethod("Update").Invoke(activeTile, objArray);
                    break;
                }
            }
        }

 3:开始在进入应用程序的时候初始化一下吧 :)

ShellTile shellTile = ShellTile.ActiveTiles.First<ShellTile>();
            if (shellTile != null)
            {

      //判断是否是wp7.8系统
                if (CheckOSVersion.IsTargetedVersion)
                {
                    CheckOSVersion.UpdateFlipTile("爱壁纸HD", "爱壁纸HD", "", "", 0, new Uri("/", UriKind.Relative), new Uri("Background.png", UriKind.RelativeOrAbsolute), new Uri("http://s.qdcdn.com/cl/10920808,256,256.jpg", UriKind.RelativeOrAbsolute), null, new Uri("bigtile.png", UriKind.RelativeOrAbsolute), null);
                }
                return;
            }
            else
            {
                return;
            }

 

 //PS :wp7.8下要想支持大磁贴的话还有一个要求就是这段代码必须得经过初始化,也就是如果 你第二次进入软件的时候你的应用才会支持

附上源码:https://files.cnblogs.com/sq62391/UpdateTile.zip

我的新浪微博::http://weibo.com/signup/signup.php?inviteCode=2477298827&c=spr_web_sq_baidub_weibo_t001

wp7/wp8 交流群(欢迎一起交流) 157153754

 

posted @ 2013-03-30 00:04  一只像鲨鱼的蜜蜂  阅读(1413)  评论(0编辑  收藏  举报