Win8.1应用开发之动态磁贴
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应用开发之动态磁贴的更多相关文章
- 【Win10 UWP】后台任务与动态磁贴
动态磁贴(Live Tile)是WP系统的大亮点之一,一直以来受到广大用户的喜爱.这一讲主要研究如何在UWP应用里通过后台任务添加和使用动态磁贴功能. 从WP7到Win8,再到Win10 UWP,磁贴 ...
- ios 开发中 动态库 与静态库的区别
使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...
- 分享:写了一个 java 调用 C语言 开发的动态库的范例
分享:写了一个 java 调用 C语言 开发的动态库的范例 cfunction.h 代码#pragma once#ifdef __cplusplusextern "C" {#e ...
- Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构
分享两篇Win 10应用开发的XML文档结构:Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构. Win 10 开发中Adapt ...
- WP8.1 Study18:动态磁贴
一.前言 动态磁贴在WindowsPhone8.1和Windows8.1都是其特色,有人喜欢有人讨厌,不过我觉得还是挺好的,可以让使用者很快知道App内的内容和吸引使用者打开App.下面来学习下怎样添 ...
- atitit.提升开发效率---动态语言总结
atitit.提升开发效率---动态语言总结 ruby,python 都不错,就是语法不好, 应用不广泛,文档,工具都非常少,不推荐... php狠不错,就是高级特性不行.. 看来子有.net/jav ...
- Win8.1应用开发之异步编程
在win8应用商店开发时,我们会遇到很多异步方法.它们存在的目的就是为了确保你的应用在运行须要大量时间的任务时仍能保持良好的响应,也就是说调用异步API是为了响应用户的操作.设想一下我们点击一个But ...
- 李洪强iOS开发之动态获取UILabel的bounds
李洪强iOS开发之动态获取UILabel的bounds 在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需 ...
- SPA项目开发之动态树+数据表格+分页
SPA项目开发之动态树+数据表格+分页 动态生成NavMenu导航菜单(只支持2级菜单) <el-menu key="" index=""> < ...
随机推荐
- Linux输入子系统(Input Subsystem)
Linux输入子系统(Input Subsystem) http://blog.csdn.net/lbmygf/article/details/7360084 input子系统分析 http://b ...
- Oracle/Mysql批量插入的sql,效率比较高
1.oracle 批量插入: insert into tableName(col1,col2,col3...) select 1,'第一行第一列值','第二列值' from dual union ...
- 项目中js调用service和procedure的办法
Ajax.js /**通用ajax服务的定义对象 * services可以是单个服务对象,也可以是service服务数组 * 具体服务的定义请参考appendServices成员函数 */ funct ...
- Binary Tree Preorder Traversal and Binary Tree Postorder Traversal
Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...
- 网站压力测试之ApacheBench
ApacheBench是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求.使用yum安装apache,ab工具在/us ...
- js 时间戳转为日期格式
原文:js 时间戳转为日期格式 js 时间戳转为日期格式 什么是Unix时间戳(Unix timestamp): Unix时间戳(Unix timestamp),或称Unix时间(Unix time) ...
- Spring boot 启动过程解析 logback
使用 Spring Boot 默认的日志框架 Logback. 所有这些 POM 依赖的好处在于为开发 Spring 应用提供了一个良好的基础.Spring Boot 所选择的第三方库是经过考虑的,是 ...
- Netflix
2009年Netflix举办了一场Netflix大奖赛.他们公开一批匿名数据,允许参赛团队使用以得出更好的算法.他们从获胜的团队中得到了现有算法10.06%的提升.Netflix本想再举行一场Netf ...
- [置顶] mybatis批量新增系列之有主键的表的批量新增
前面介绍了无主键的表的批量插入,文章地址:http://blog.csdn.net/zhouxiaoyun0228/article/details/9980181 但是在开发中往往许多的表是需要主键的 ...
- Shell脚本运行hive语句 | hive以日期建立分区表 | linux schedule程序 | sed替换文件字符串 | shell推断hdfs文件文件夹是否存在
#!/bin/bash source /etc/profile; ################################################## # Author: ouyang ...