Win8.1应用开发之动态磁贴
2016-01-26 09:48
375 查看
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;
相关文章推荐
- Maven进价:Maven的生命周期阶段
- InstallShield高级应用--检查是否安装ORACLE或SQL Server
- shell中${}的妙用
- 浅谈OO思想
- JS正则表达式比较常见用法
- appium1.3.7的坑-Original error: Could not initialize ideviceinstaller; make sure it is installed
- iOS开发笔记--UIImageView的属性之animationImages详解
- GetLogicalDriveStrings
- Linux查看CPU和内存使用情况
- OpenGL官方教程——着色器语言概述
- mysql常用操作
- 2016太原UI设计师郭文军图标的制作原则,面试必考
- Spring Boot+Spring Data JPA+Spring Cache
- 深入了解LayoutInflater
- 两种方式获取Thrift调用的客户端IP地址
- iOS开发笔记--UILabel显示不同的字体和颜色
- WebGL利用FBO完成立方体贴图效果完整实例(附demo源码下载)
- Xcode 插件优缺点对比(推荐 20 款插件)
- JDK中的URLConnection参数详解(转)
- Linux常用命令大全