• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

让你的应用在WP7.8系统下支持大磁贴代码演示

时间:2015年04月02日 15:22:52    来源:魔法猪系统重装大师官网    人气:15264

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();
            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下要想支持大磁贴的话还有一个要求就是这段代码必须得经过初始化,也就是如果 你第二次进入软件的时候你的应用才会支持

附上源码:http://pan.baidu.com/share/link?shareid=476410&uk=85241834

让,你的,应,用在,WP7.8,系统,下,支持,大磁,贴,
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部