using demo02.Common;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.ApplicationSettings;
using System.Threading.Tasks;
using Windows.UI.Notifications;
using demo02.DataStructure;
using Windows.Data.Xml.Dom;
using Windows.Storage.Streams;
using Windows.Storage;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage.Pickers;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using demo02.Helper;
using WhereWeGo.Helper;
using System.Net.Http;
using System.Net;
using Windows.Networking.PushNotifications;
using Microsoft.WindowsAzure.Messaging; //“中心应用程序”模板在 http://go.microsoft.com/fwlink/?LinkId=321221 上有介绍 namespace demo02
{ sealed partial class App : Application
{ public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
} protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null)
{
rootFrame = new Frame();
SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
try
{
await SuspensionManager.RestoreAsync();
}
catch (SuspensionManagerException)
{ }
} SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
Window.Current.Content = rootFrame;
} if (rootFrame.Content == null)
{ rootFrame.Navigate(typeof(HubPage), e.Arguments);
} await ConfigureNotifications(); //动态磁贴的调用 Window.Current.Activate();
} private async static Task ConfigureNotifications()
{
// Send local notifications
//TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueueForSquare310x310(true); var topRated = await demo02.DataModel.WWGDataSource.GetTileUAsync(); //获得动态磁贴的数据来源 foreach (var recipe in topRated.Universities) //topRated.Universities是个ObservableCollection<OfflinePicUri>
{
var templateContent = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare310x310BlockAndText02); //设定动态磁贴採用的模板 //将图片绑定到动态磁贴上
//特别注意:图片不能太大,否则不能显示
var imageAttributes = templateContent.GetElementsByTagName("image");
((XmlElement)imageAttributes[0]).SetAttribute("src", "ms-appx:///" + recipe.TileImagePath);
//System.Diagnostics.Debug.WriteLine(recipe.TileImagePath);
((XmlElement)imageAttributes[0]).SetAttribute("alt", recipe.Name); //给动态磁贴加入文字
var tileTextAttributes = templateContent.GetElementsByTagName("text");
tileTextAttributes[1].InnerText = recipe.Name;
//tileTextAttributes[3].InnerText = "Brief Info";
tileTextAttributes[4].InnerText = recipe.Summary;
//tileTextAttributes[5].InnerText = recipe.Summary;
tileTextAttributes[6].InnerText = recipe.Stars + " stars"; //这里要特别注意:要使得各Id互不同样,否则会显示不出
var tileNotification = new TileNotification(templateContent);
tileNotification.Tag = recipe.Id; TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); } } } } /*********************************************************************************/ //附上:上面topRated.Universities集合中元素University的类 /*********************************************************************************/
using demo02.Helper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace demo02.DataModel
{ public class University : Base
{ public University(String id, String name, String summary, String imagePath, String category, double stars, String tileImagePath)
: base(id, name, summary, imagePath)
{
this.Category = category;
this.Stars = stars;
this.Projects = new ObservableCollection<Project>();
this.Images = new ImageHelper();
this.TileImagePath = tileImagePath;
} public string TileImagePath { get; set; }
public string Category { get; set; }
public double Stars { get; set; }
public ObservableCollection<Project> Projects { get; set; } public int ClickTimes { get; set; }
//兼容
public ImageHelper Images { get; set; } } }

要注意,同台磁贴用到的namespace有:

using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using System.Threading.Tasks;

Win8.1应用开发之动态磁贴的更多相关文章

  1. 【Win10 UWP】后台任务与动态磁贴

    动态磁贴(Live Tile)是WP系统的大亮点之一,一直以来受到广大用户的喜爱.这一讲主要研究如何在UWP应用里通过后台任务添加和使用动态磁贴功能. 从WP7到Win8,再到Win10 UWP,磁贴 ...

  2. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  3. 分享:写了一个 java 调用 C语言 开发的动态库的范例

    分享:写了一个 java 调用 C语言 开发的动态库的范例 cfunction.h   代码#pragma once#ifdef __cplusplusextern "C" {#e ...

  4. Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构

    分享两篇Win 10应用开发的XML文档结构:Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构. Win 10 开发中Adapt ...

  5. WP8.1 Study18:动态磁贴

    一.前言 动态磁贴在WindowsPhone8.1和Windows8.1都是其特色,有人喜欢有人讨厌,不过我觉得还是挺好的,可以让使用者很快知道App内的内容和吸引使用者打开App.下面来学习下怎样添 ...

  6. atitit.提升开发效率---动态语言总结

    atitit.提升开发效率---动态语言总结 ruby,python 都不错,就是语法不好, 应用不广泛,文档,工具都非常少,不推荐... php狠不错,就是高级特性不行.. 看来子有.net/jav ...

  7. Win8.1应用开发之异步编程

    在win8应用商店开发时,我们会遇到很多异步方法.它们存在的目的就是为了确保你的应用在运行须要大量时间的任务时仍能保持良好的响应,也就是说调用异步API是为了响应用户的操作.设想一下我们点击一个But ...

  8. 李洪强iOS开发之动态获取UILabel的bounds

    李洪强iOS开发之动态获取UILabel的bounds 在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需 ...

  9. SPA项目开发之动态树+数据表格+分页

    SPA项目开发之动态树+数据表格+分页 动态生成NavMenu导航菜单(只支持2级菜单) <el-menu key="" index=""> < ...

随机推荐

  1. C# 模拟提交带附件(input type=file)的表单

    今天调用某API时,对于文档中的传入参数:File[] 类型,感觉很陌生,无从下手! 按通常的方式在json参数中加入file的二进制数据提交,一直报错(参数错误)!后来经过多方咨询,是要换一种 表单 ...

  2. c# 流程控制

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. 高级UNIX环境编程4 文件和目录

    #include<sys/stat.h> stat fstat lstat fchmod 对已打开的文件操作

  4. 转: cmd和amd的区别

    AMD 规范在这里:https://github.com/amdjs/amdjs-api/wiki/AMDCMD 规范在这里:https://github.com/seajs/seajs/issues ...

  5. 地精排序(Gnome Sort) 算法

    gnome应该是最简单排序的排序算法吧!Gnome Sort,这是该算法的作者命名的,O(n*n)时间复杂度,O(1)空间复杂度,属于稳定的排序算法.算法的思想是每趟循环找到第一个逆序的元素,把它和在 ...

  6. android 修改背景色(转)

    修改为黑底白字 修改AndroidManifest.xml把android:theme="@style/AppTheme" 修改为android:theme="@andr ...

  7. linux内核源码阅读之facebook硬盘加速flashcache之三

    上一节讲到在刷缓存的时候会调用new_kcahed_job创建kcached_job,由此我们也可以看到cache数据块与磁盘数据的对应关系.上一篇:http://blog.csdn.net/lium ...

  8. 在Update Panel 控件里面添加 File Upload 控件 上传文件

    Detail Information:http://www.codeproject.com/Articles/482800/FileplusUploadplusinplusUpdateplusPane ...

  9. win8系统特别慢的基本判断方法

    单位有6,7台同事的电脑是win8.1.不知道什么原因,两位领导反映电脑特别慢. 我查看了一下,确实很慢. 虽然知道win8系统不好,但也不至于这样. 打开任务管理器,看了一下cpu和内存的使用状态, ...

  10. CodeForces 546D Soldier and Number Game 打表(求质因子个数)

    题目:戳我这个题与HDUOJ 5317有异曲同工之妙 题意:题意看懂了上面的一大串英文之后其实很简单,就是给你一个正整数n,问你n有多少个质因子,不过这里n是通过a!/b!给定的,也就是说n=(a!/ ...