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=""> < ...
随机推荐
- BZOJ 2748 音量调节
这道题我开始做时想用搜索来做,但是失败了,后来仔细一想发现这就是一个背包问题,之后一切就简单多了. 代码如下: #include<cstdio> #includ ...
- 微信开放平台 获取 component_verify_ticket
<?php /** * @author zhaozhuobin * @date:2016-06=07 * */ namespace common\components;use DOMDocume ...
- office2013破解工具
终于找到破解工具了,每次打开word文档都弹出限期激活对话框,真的是相当烦躁啊,先把破解工具奉上!!!! 工具名: HEU-KMS-ActivatorV1.1绿色版 链接: office2013 和 ...
- Android外部存储 - 官方文档解读
预备知识:External Storage Technical Information 摘要: "The WRITE_EXTERNAL_STORAGE permission must onl ...
- poj 3176 Cow Bowling(区间dp)
题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...
- HDoj-1527-取石子游戏
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- BZOJ 2654: tree( 二分 + MST )
我们给白色的边增加权值 , 则选到的白色边就会变多 , 因此可以二分一下. 不过这道题有点小坑... ------------------------------------------------- ...
- javascript 学习随笔6
改变html内容 document.getElementById("p1").innerHTML="New text!"; var element=docume ...
- PHP使用纯真IP数据库
#纯真数据库调用函数(需要下载纯真数据库文件) function convertip($ip) { $ip1num = 0; $ip2num = 0; $ipAddr1 =""; ...
- Python 迭代器、生成器、递归、正则表达式 (四)
一.迭代器&生成器 1.迭代器仅仅是一容器对象,它实现了迭代器协议.它有两个基本方法: 1)next 方法 返回容器的下一个元素 2)_iter_方法 返回迭代器自身.迭代器可以使用内建的it ...