zoukankan      html  css  js  c++  java
  • 【WP7】WP7.8使用WP8的磁贴

      微软之前表示,对于所有WP7设备都可以升级到7.8,不过对于7.8,新加的东西实在太少了,只加入了类似WP8的界面,其他几乎没有变化,下面说说关于WP7.8中磁贴的使用

    WP7的磁贴是属性实在太有限,只能设置Title,和Background和Count,而且大小不能改变

    在WP8中有三种磁贴可以使用,循环图块,图标图块,翻转图块,关于这三种图块MSDN上说的很详细,这里不多介绍,地址如下

          http://msdn.microsoft.com/zh-CN/library/windowsphone/develop/hh202948(v=vs.105).aspx

      http://www.developer.nokia.com/Community/Wiki/Live_Tile_Templates_in_Windows_Phone_8

     使用WP8的磁贴,必须通过反射的方式进行调用,因为默认为WP7.5的库,不带这几个类,但是WP7.8模拟器和WP7.8手机上有这几个类

    1、首先判断当前系统版本,WP7.5和WP7.5以下的系统不支持

                private static readonly Version _targetedVersion8 = new Version(8, 0);
                private static readonly Version _targetedVersion78 = new Version(7, 10, 8858);
    
                //判断系统版本是否高于7.8
                public static bool CanUseLiveTiles
                {
                    get { return Environment.OSVersion.Version >= _targetedVersion78; }
                }
    
                public static bool IsWP8
                {
                    get { return Environment.OSVersion.Version >= _targetedVersion8; }
                }

    2、通过反射调用

      关于反射的使用,可以参考下面帖子,这里不详细说明

         http://www.cnblogs.com/bomo/archive/2013/03/16/2962430.html

      通过反射获得类,下面演示 CycleTileData 图块的使用,FlipTileData 和 IconicTileData 的使用差不多,这里就不演示了

            string title = "cycletiletitle";
            int count = 20;
            Uri navigateduri = new Uri("/MainPage.xaml", UriKind.Relative);
            //是否支持长图块
            bool usewide = true;
    
            //获取到CycleTileData类型
            Type tileDataType = Type.GetType("Microsoft.Phone.Shell.CycleTileData, Microsoft.Phone");
            //调用构造函数创建CycleTileData实例
            object cycleTileData = tileDataType.GetConstructor(new Type[] { }).Invoke(null);
    
            //获取属性设置函数设置属性
            MethodInfo setMethod = cycleTileData.GetType().GetProperty("Title").GetSetMethod();
            setMethod.Invoke(cycleTileData, new object[] { title });
            setMethod = cycleTileData.GetType().GetProperty("Count").GetSetMethod();
            setMethod.Invoke(cycleTileData, new object[] { count });
            setMethod = cycleTileData.GetType().GetProperty("SmallBackgroundImage").GetSetMethod();
            setMethod.Invoke(cycleTileData, new object[] { new Uri("/Assets/logo159x159.png", UriKind.Relative) }); 
            setMethod = cycleTileData.GetType().GetProperty("CycleImages").GetSetMethod();
            setMethod.Invoke(cycleTileData, new object[] { new List<Uri> { new Uri("/Assets/Image1.png", UriKind.Relative), new Uri("/Assets/Image2.png", UriKind.Relative), new Uri("/Assets/Image3.png", UriKind.Relative) } });
    
    Type shellTileType
    = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone"); MethodInfo createmethod = shellTileType.GetMethod("Create", new[] { typeof(Uri), typeof(ShellTileData), typeof(bool) }); createmethod.Invoke(null, new object[] { navigateduri, cycleTileData, usewide });

        

       关于WP7.8的Tile使用,在CodePlex上有个项目对Tile进行了封装,这里介绍下该库的用法用法

        http://mangopollo.codeplex.com/

      1、Utils类用于判断当前设备是否支持WP8磁贴

        两个属性:  CanUseLiveTiles(系统版本大于7.8) 和IsWP8(WP8设备)

      2、三种磁贴的类,CycleTileData ,FlipTileData,IconicTileData

        属性和用法都和WP8一

      3、管理磁贴的类:ShellTileExt

    下面演示生成FlipTileData的用法

            //判断是否支持
            if (!Utils.CanUseLiveTiles)
            {
                MessageBox.Show("This feature needs Windows Phone 8");
                return;
            }
    
            try
            {
                var mytile = new FlipTileData
                {
                    Title = "wide flip tile",
                    BackTitle = "created by",
                    BackContent = "Rudy Huyn",
                    Count = 9,
                    SmallBackgroundImage = new Uri("/Assets/logo159x159.png", UriKind.Relative),
                    BackgroundImage = new Uri("/Assets/Background336x336_1.png", UriKind.Relative),
                    BackBackgroundImage = new Uri("/Assets/Background336x336_2.png", UriKind.Relative)
                };
                //创建磁贴
                ShellTileExt.Create(new Uri("/MainPage.xaml?msg=from%20flip%20tile", UriKind.Relative), mytile, true);
            }
            catch
            {
                MessageBox.Show("remove tile before create it again");
            }

      通过该库,我们可以很方便的在WP7.8上创建WP8磁贴

      学习不是让我们再造一个轮子,而是教会我们如何造轮子,并且利用别人的轮子创造自己的东西

    最后附上库文件

       https://files.cnblogs.com/bomo/Mangopollo.Light.zip

  • 相关阅读:
    用css实现网页背景渐变的代码
    表格特效代码 立体表格 圆角表格 变色的单元格
    谷歌地图离线包尝试
    opensoial google社会化网络API
    在自己网站嵌入各大搜索引擎代码
    利用谷歌搜索建立自己的站内搜索引擎
    Jquery学习
    网站备案 ICP备案流程
    了解JavaScript的类和对象
    QeePHP中modules下的模块ACL配置规则
  • 原文地址:https://www.cnblogs.com/bomo/p/2962275.html
Copyright © 2011-2022 走看看