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=""> < ...
随机推荐
- REF CURSOR和CURSOR
REF CURSOR DECLARE TYPE TY_EMP_CUR IS REF CURSOR; V_Emp_Cur TY_EMP_CUR; V_Id EMP.ID%TYPE; BEGIN OPEN ...
- 手把手教你图片转ASCII码图
效果图 基本思路 把图片每个像素点的信息拿出来,最重要的是拿到rgb的值 把每个像素点由rgb转成灰度图像,即0-255 给0-255分级,把每个等级的像素点转换成ascii码,完成 实现 第一步:获 ...
- Linux上MongoDB的安装与配置
长话短说,一共有两种方法.(我随便选了一个发行版Mint) 一.apt-get方法 官网上说的很清楚: http://docs.mongodb.org/manual/tutorial/install- ...
- 用PHP编写Hadoop的MapReduce程序
用PHP编写Hadoop的MapReduce程序 Hadoop流 虽然Hadoop是用Java写的,但是Hadoop提供了Hadoop流,Hadoop流提供一个API, 允许用户使用任何语言编 ...
- 1297 - Largest Box(三分)
1297 - Largest Box PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In t ...
- AWS要进入中国了
去年底就开始有这个传言见诸于某些媒体,说网站支持中文了要进中国了,也有说这不代表什么是谣言 这几天又听到有消息说比较靠谱就半年内的事儿 其实如果没有政策阻碍的话进中国是迟早的事情,原因如下 Amazo ...
- 中国A股市场缘何遭遇9连跌?
端午长假刚过,当投资者对“红六月”预期信心满满的时候,A股市场却遭遇了诡异的跌势,截止6月17日收盘,A股出现了罕见的“9连跌”.不仅上证综指失守2200点年线整数位,深证成指跌幅则高达3%以上,而且 ...
- C程序设计语言之一
%d 按照十进制整形数打印: %o 按照八进制整形数打印: %x 按照十六进制整形数打印: %c 表示字符 %s 表示字符串 %% 表示%本身打印: %ld long型输出 ”幻数“: #define ...
- windows下取linux系统里面的文件
方法一:使用原生态的psftp 1.下载psftp.exe http://pan.baidu.com/s/1boVLHKF 2.双击psftp.exe 2.1 输入指令:open IP地址 (例如:o ...
- iOS 日历控件
近期需要写一个交互有点DT的日历控件,具体交互细节这里略过不表. 不过再怎么复杂的控件,也是由基础的零配件组装起来的,这里最基本的就是日历控件. 先上图: 从图中可以看出日历控件就是由一个个小方块组成 ...