Windows Phone 8.1 Tiles, Notifications and Action Center
生活随笔
收集整理的這篇文章主要介紹了
Windows Phone 8.1 Tiles, Notifications and Action Center
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(1)Tiles
Tiles 也就是磁貼,是 Windows Phone 的一大特色。
一個 Tile 其實可以看成是一個 XML,比如:
<tile><visual><binding template="TileSquareImage"><image id="1" src="image1" alt="alt text"/></binding> </visual> </tile><tile><visual version="2"><binding template="TileSquare150x150Image" fallback="TileSquareImage"><image id="1" src="image1" alt="alt text"/></binding> </visual> </tile>微軟為我們提供了一系列模板,具體可參照:鏈接
只要根據模板的 XML 格式,便可輕松的更新 Tile:
private void updateButton_Click(object sender, RoutedEventArgs e) {UpdateTiles("ms-appx:///Images/Middle.png", "ms-appx:///Images/Wide.png"); }private void UpdateTiles(string middlePath, string widePath) {string tileString = "<tile>" +"<visual version=\"2\">" +"<binding template=\"TileSquare150x150PeekImageAndText04\" fallback=\"TileSquarePeekImageAndText04\">" +"<image id=\"1\" src=\"" + middlePath + "\" alt=\"alt text\"/>" +"<text id=\"1\"></text>" +"</binding>" +"<binding template=\"TileWide310x150ImageAndText01\" fallback=\"TileWideImageAndText01\">" +"<image id=\"1\" src=\"" + widePath + "\" alt=\"alt text\"/>" +"<text id=\"1\"></text>" +"</binding>" +"</visual>" +"</tile>";XmlDocument tileXML = new XmlDocument();tileXML.LoadXml(tileString);TileNotification newTile = new TileNotification(tileXML);TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();updater.EnableNotificationQueue(false);updater.Update(newTile); }除了主磁貼外我們還可以新建 SecondaryTile:
private void createButton_Click(object sender, RoutedEventArgs e) {CreateTile("ms-appx:///Images/Middle.png", "ms-appx:///Images/Wide.png"); }private async void CreateTile(string middlePath, string widePath) {SecondaryTile tile = new SecondaryTile("Cortana", "Cortana", "Some", new Uri(middlePath), TileSize.Default);tile.VisualElements.ShowNameOnSquare150x150Logo = true;tile.VisualElements.ForegroundText = ForegroundText.Dark;tile.VisualElements.Square30x30Logo = new Uri(middlePath);tile.VisualElements.Wide310x150Logo = new Uri(widePath);await tile.RequestCreateAsync(); }SecondaryTile 的更新與主磁貼更新一樣:
TileUpdater update = TileUpdateManager.CreateTileUpdaterForSecondaryTile("Cortana");?
(2)Notifications
Notification(推送通知)分為 Tile,Badge,Toast,Raw 四種類型,而通知的方式又分為 Scheduled,Periodic,Local,Push 四種,它們之間對應的關系為:
使用方法都大同小異,根據各自的 XML 格式修改再調用 Update 方法即可,例如:
XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04); ToastNotification toast = new ToastNotification(xml); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast);需要注意的是:(1)Toast 通知需要在 Manifest 中許可;(2)Push 方法為:
private async void SendRawNotification() {var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();channel.PushNotificationReceived += channel_PushNotificationReceived; }private void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) {var raw = args.RawNotification; }?
(3)Action Center
1)每個應用最多可以在 Action Center 中駐留 20 條通知
2)通知最多可駐留 7 天
3)可發送靜默通知(不會提示用戶)
toast1.SuppressPopup = true;4)可對通知進行分組
XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04);ToastNotification toast1 = new ToastNotification(xml); toast1.Group = "One"; toast1.Tag = "1";5)可更新或刪除通知(可刪除某一組)
ToastNotificationManager.History.RemoveGroup("One");?
轉載于:https://www.cnblogs.com/xiaoshi3003/p/3764507.html
總結
以上是生活随笔為你收集整理的Windows Phone 8.1 Tiles, Notifications and Action Center的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 学习写架构必会几大技术点
- 下一篇: execl中一串字符,以某个分隔符分开,