原文:与众不同 windows phone (8) - Tile(磁贴)

[索引页]
[源码下载]

与众不同 windows phone (8) - Tile(磁贴)

作者:webabcd

介绍
与众不同 windows phone 7.5 (sdk 7.1) 之磁贴

  • 概述
  • 演示如何创建、更新、删除磁贴
  • 演示如何按计划更新磁贴的正面背景图

示例
1、创建、更新、删除磁贴的 Demo
ShellTileDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Tile.ShellTileDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"> <StackPanel Orientation="Vertical">
<TextBlock Name="lblMsg" />
<Button Name="btnUpdateApplicationTile" Content="更新 Application Tile" Click="btnUpdateApplicationTile_Click" />
<Button Name="btnCreateSecondaryTile" Content="创建 Secondary Tile(可以创建多个)" Click="btnCreateSecondaryTile_Click" />
<Button Name="btnDeleteSecondaryTile" Content="删除全部 Secondary Tile" Click="btnDeleteSecondaryTile_Click" />
</StackPanel> </phone:PhoneApplicationPage>

ShellTileDemo.xaml.cs

/*
* Tile - 磁贴
* Tile 的大小是173 * 173;宽 Tile 的大小 356 * 173,需要把 manifest 中的 <TemplateType5> 修改为 <TemplateType6>,但是不会通过微软审核
* Tile 分为应用程序磁贴(Application Tile)和次要磁贴(Secondary Tile)
* 程序无虑如何都有一个 Application Tile(无论它是否被固定到了开始屏幕),只能更新它(不能创建和删除);而 Secondary Tile 是可以创建、更新和删除的,Secondary Tile 如果存在一定是在开始屏幕上
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; namespace Demo.Tile
{
public partial class ShellTileDemo : PhoneApplicationPage
{
public ShellTileDemo()
{
InitializeComponent();
} protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// 演示获取点击 Tile 后传递过来的参数数据
if (NavigationContext.QueryString.Count > )
lblMsg.Text = "参数 t 的值为:" + this.NavigationContext.QueryString["t"]; base.OnNavigatedTo(e);
} private void btnUpdateApplicationTile_Click(object sender, RoutedEventArgs e)
{
/*
* StandardTileData - 用于描述 Tile 的数据
* Title - 正面标题
* BackgroundImage - 正面背景
* Count - 正面显示的 badge (徽章),范围 1 - 99
* BackTitle - 背面标题
* BackBackgroundImage - 背面背景
* BackContent - 背面内容
*
*
* ShellTile - 用于管理应用程序Tile和次要Tile
* Update(StandardTileData data) - 使用指定的 Tile 数据更新已有的 Tile 信息
* Delete() - 删除此 Tile
* NavigationUri - 此 Tile 的导航地址
*
* ShellTile.ActiveTiles - 固定到开始屏幕的 Tile 集合。注意:其第一个元素必然是 application tile,无论其是否被固定到了首页
* ShellTile.Create(Uri navigationUri, ShellTileData initialData) - 创建一个新的 Secondary Tile(如果有 Secondary Tile,其必然是被固定到开始屏幕的)
* navigationUri - 点击 Tile 后所导航到的地址,此值相当于 key 值,不能重复
* initialData - 需要创建的 Tile 数据
*/ /*
* 注意:
* 创建次要磁贴时背景图必须使用本地资源(程序包内或独立存储中,如果是独立存储则图像必须位于 Shared/ShellContent)
* 更新应用程序磁贴或次要磁贴时,可以使用本地资源或远程资源来更新背景图像
* 磁贴图像可以是 jpg 或 png 或 gif(只显示第一帧),png 或 gif 的透明区域的背景会呈现主题色
* 当使用远程图像时,不能是https,要小于80KB,必须30秒内下载完
*/ // 创建应用程序 Tile 的 Demo
ShellTile applicationTile = ShellTile.ActiveTiles.First(); StandardTileData newTile = new StandardTileData
{
Title = "App Fore Tile Title",
BackgroundImage = new Uri("TileBackgroundBlue.png", UriKind.Relative),
Count = ,
BackTitle = "App Back Tile Title",
BackBackgroundImage = new Uri("TileBackgroundGreen.png", UriKind.Relative),
BackContent = "App Back Tile Content" + Environment.NewLine + "OK"
}; applicationTile.Update(newTile);
} private void btnCreateSecondaryTile_Click(object sender, RoutedEventArgs e)
{
// 创建次要 Tile 的 Demo
StandardTileData newTile = new StandardTileData
{
Title = "Secondary Fore Tile Title",
BackgroundImage = new Uri("TileBackgroundBlue.png", UriKind.Relative),
Count = ,
BackTitle = "Secondary Back Tile Title",
BackBackgroundImage = new Uri("TileBackgroundGreen.png", UriKind.Relative),
BackContent = "Secondary Back Tile Content" + Environment.NewLine + "OK"
}; // uri 是 key 不能重复
ShellTile.Create(new Uri("/Tile/ShellTileDemo.xaml?t=" + DateTime.Now.Ticks.ToString(), UriKind.Relative), newTile);
} private void btnDeleteSecondaryTile_Click(object sender, RoutedEventArgs e)
{
// 删除全部次要磁贴
if (ShellTile.ActiveTiles.Count() > )
{
ShellTile lastTile = ShellTile.ActiveTiles.Last();
lastTile.Delete();
} // xna 关闭应用程序:Microsoft.Xna.Framework.Game.Exit();
// sl 关闭应用程序
throw new Exception();
}
}
}

2、按计划更新磁贴的正面背景图的 Demo
ShellTileScheduleDemo.xaml

<phone:PhoneApplicationPage
x:Class="Demo.Tile.ShellTileScheduleDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"> <StackPanel Orientation="Vertical">
<Button Name="btnStart" Content="Start Schedule" Click="btnStart_Click" />
<Button Name="btnStop" Content="Stop Schedule" Click="btnStop_Click" />
</StackPanel> </phone:PhoneApplicationPage>

ShellTileScheduleDemo.xaml.cs

/*
* ShellTileSchedule - 用于按计划更新磁贴的正面背景图
* new ShellTileSchedule() - 更新 Application Tile
* new ShellTileSchedule(ShellTile tile) - 更新指定的 Secondary Tile
*
* Recurrence - 更新计划的模式
* UpdateRecurrence.Interval - 定时更新
* UpdateRecurrence.Onetime - 只更新一次
* Interval - 定时更新时的更新间隔(只能是 每小时/每天/每星期/每月)
* MaxUpdateCount - 最大的更新次数(默认值是 0,即无限次更新)
* StartTime - 开始更新的时间
* RemoteImageUri - 需要更新的图像的远程地址
*
* Start() - 启动计划
* Stop() - 停止计划
*
*
* 注意:
* 具体更新时间点是由系统统一调度的(系统每隔一段时间会批处理所有程序的更新计划,这么做是为了省电),也就是说即使你设置了 StartTime = DateTime.Now,也不会马上更新,但是一个小时内应该会更新
* 如果更新计划失败(比如找不到远程图像,远程图像大于80KB,超过30秒还没下载完等)次数太多,则该更新计划会被系统自动取消
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; namespace Demo.Tile
{
public partial class ShellTileScheduleDemo : PhoneApplicationPage
{
private ShellTileSchedule _schedule = new ShellTileSchedule(); public ShellTileScheduleDemo()
{
InitializeComponent();
} private void btnStart_Click(object sender, RoutedEventArgs e)
{
_schedule.Recurrence = UpdateRecurrence.Interval;
_schedule.Interval = UpdateInterval.EveryHour;
_schedule.StartTime = DateTime.Now;
//_schedule.MaxUpdateCount = 100;
_schedule.RemoteImageUri = new Uri(@"http://image.sinajs.cn/newchart/small/nsh000300.gif");
_schedule.Start();
} private void btnStop_Click(object sender, RoutedEventArgs e)
{
_schedule.Stop();
}
}
}

OK
[源码下载]

与众不同 windows phone (8) - Tile(磁贴)的更多相关文章

  1. 与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息

    原文:与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息 [索引页][源码下载] 与众不同 windows ph ...

  2. 与众不同 windows phone (36) - 8.0 新的瓷贴: FlipTile, CycleTile, IconicTile

    [源码下载] 与众不同 windows phone (36) - 8.0 新的瓷贴: FlipTile, CycleTile, IconicTile 作者:webabcd 介绍与众不同 windows ...

  3. 与众不同 windows phone (47) - 8.0 其它: 锁屏信息和锁屏背景, 电池状态, 多分辨率, 商店, 内置协议, 快速恢复

    [源码下载] 与众不同 windows phone (47) - 8.0 其它: 锁屏信息和锁屏背景, 电池状态, 多分辨率, 商店, 内置协议, 快速恢复 作者:webabcd 介绍与众不同 win ...

  4. 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl

    [源码下载] 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl 作者:webabcd 介绍与众不同 windows p ...

  5. 与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成

    原文:与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成 [索引页][源码下载] 与众不同 win ...

  6. 与众不同 windows phone (12) - Background Task(后台任务)之 PeriodicTask(周期任务)和 ResourceIntensiveTask(资源密集型任务)

    原文:与众不同 windows phone (12) - Background Task(后台任务)之 PeriodicTask(周期任务)和 ResourceIntensiveTask(资源密集型任 ...

  7. 与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知

    原文:与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知 [索引页][源码下载] 与众不同 windows phone ( ...

  8. 与众不同 windows phone (6) - Isolated Storage(独立存储)

    原文:与众不同 windows phone (6) - Isolated Storage(独立存储) [索引页][源码下载] 与众不同 windows phone (6) - Isolated Sto ...

  9. 与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密

    原文:与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密 [索引页][源码下载] 与众不同 wi ...

随机推荐

  1. 详解iOS7升级细节:引领视觉革命

    下星期我们将看到的正式版将和WWDC上看到的大不相同.苹果六月份发布了全新版本的iOS操作系统——这是从2007年首次发布以来的最大的一次调整和改进.这次的改变招致许多批评.许多设计师在网站上晒出了他 ...

  2. Android中文API(129) —— AudioManager

    前言 本章内容是android.media.AudioManager,版本为Android 3.2 r1,翻译来自"文炜",欢迎访问他的博客:"http://www.cn ...

  3. vector的成员函数解析

    vector是线性容器,它的元素严格的依照线性序列排序,和动态数组非常相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅能够使用迭代器(iterator)訪问元素,还能够使用指针 ...

  4. HDU 5009 DP

    2014 ACM/ICPC Asia Regional Xi'an Online 对于N个数 n(1 ≤ n ≤ 5×104), 把N个数分成随意个区间,每一个区间的值是该区间内不同数字个数的平方和, ...

  5. SQL__用命令删除定期的备份数据库文件

    用计划任务可以定期执行下列语句: FORFILES /P e:\test /M *.bak /C "cmd /C del /Q @path" /d -4 其中可更换目录与文件类型. ...

  6. KeyValuePair用法(转)

    转载自:http://blog.sina.com.cn/s/blog_9741eba801016w61.html C# KeyValuePair<TKey,TValue>的用法.结构体,定 ...

  7. CentOS 如何安装git server + Gitolite 【配置不成功需要再测试2015-8-20】

    安装git 关于安装git  可以参考 http://gitolite.com/gitolite/install.html 里面有官方的介绍 1. Git 的工作需要调用 curl,zlib,open ...

  8. QList 和std::list的比较

    QList QList<T> 是一个Qt通用容器类.它存储一序列的值,并且提供基于索引的数据访问方法和快速的插入和删除操作. QList<T>, QLinkedList< ...

  9. [思路]为什么要做一个Web服务器

    对于.net开发者而言,提到Web服务器最容易想到的就是IIS了. IIS功能强大,配置繁多,但不免对普通用户而言过于复杂,另外在云时代的今天,同时维护多个IIS或远程维护IIS还是有诸多不便的,有很 ...

  10. JavaScript实现复制功能

    这两天在做Web前端时,遇到需求通过 js 实现文本复制的功能. 先不考虑浏览器的兼容性,看看各浏览器对复制功能的支持情况: 1.IE浏览器 ,解决方法有三种,代码如下: function copy( ...