windows8开发笔记(2)通知

     Windows8商店应用的 通知 分为三种类型:

     Badge(锁屏提醒):通知锁屏提醒可传达有关应用或应用特定的摘要或状态信息。这些信息可以是数字 (1-99) 或 Windows 所提供的一组字形中的一个。

MSDN:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh779719.aspx

示例代码:

   1: void UpdateBadgeWithNumber(int number)
   2:     {
   3:         // Note: This sample contains an additional project, NotificationsExtensions.
   4:         // NotificationsExtensions exposes an object model for creating notifications, but you can also modify the xml
   5:         // of the notification directly. See the additional function UpdateBadgeWithNumberWithStringManipulation to see how to do it
   6:         // by modifying strings directly
   7:  
   8:         BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent((uint)number);
   9:  
  10:         // send the notification to the app's application tile
  11:         BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeContent.CreateNotification());
  12:  
  13:      
  14:     }

     Toast 通知:Toast 通知是在屏幕右上角(对于从右到左 (RTL) 方向的语言,则位于左上角)显示的通知,它让应用可以告知用户他/她是在另一个应用中、在“开始”屏幕上,还是在桌面上。

MSDN:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh779727.aspx 
示例代码:

   1: string toastXmlString = String.Empty;
   2:            if (templateType == ToastTemplateType.ToastText01)
   3:            {
   4:                toastXmlString = "<toast>"
   5:                               + "<visual version='1'>"
   6:                               + "<binding template='ToastText01'>"
   7:                               + "<text id='1'>Body text that wraps over three lines</text>"
   8:                               + "</binding>"
   9:                               + "</visual>"
  10:                               + "</toast>";
  11:            }
  12:            else if (templateType == ToastTemplateType.ToastText02)
  13:            {
  14:                toastXmlString = "<toast>"
  15:                               + "<visual version='1'>"
  16:                               + "<binding template='ToastText02'>"
  17:                               + "<text id='1'>Heading text</text>"
  18:                               + "<text id='2'>Body text that wraps over two lines</text>"
  19:                               + "</binding>"
  20:                               + "</visual>"
  21:                               + "</toast>";
  22:            }
  23:            else if (templateType == ToastTemplateType.ToastText03)
  24:            {
  25:                toastXmlString = "<toast>"
  26:                               + "<visual version='1'>"
  27:                               + "<binding template='ToastText03'>"
  28:                               + "<text id='1'>Heading text that is very long and wraps over two lines</text>"
  29:                               + "<text id='2'>Body text</text>"
  30:                               + "</binding>"
  31:                               + "</visual>"
  32:                               + "</toast>";
  33:            }
  34:            else if (templateType == ToastTemplateType.ToastText04)
  35:            {
  36:                toastXmlString = "<toast>"
  37:                               + "<visual version='1'>"
  38:                               + "<binding template='ToastText04'>"
  39:                               + "<text id='1'>Heading text</text>"
  40:                               + "<text id='2'>First body text</text>"
  41:                               + "<text id='3'>Second body text</text>"
  42:                               + "</binding>"
  43:                               + "</visual>"
  44:                               + "</toast>";
  45:            }
  46:  
  47:            Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
  48:            toastDOM.LoadXml(toastXmlString);

     Tile(辅助磁贴):辅助磁贴使用户能够将 Windows 应用商店应用的特定内容和深层链接—对固定应用内部一个特定位置的引用—发送到“开始”屏幕上。辅助磁贴使用户能够使用好友、新闻源、股票报价和其他对其很重要的内容来个性化“开始”屏幕体验。

MSDN:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh465372.aspx

示例代码:

   1: // create a string with the tile template xml
   2:            string tileXmlString = "<tile>"
   3:                              + "<visual>"
   4:                              + "<binding template='TileWideImageAndText01'>"
   5:                              + "<text id='1'>This tile notification uses ms-appx images</text>"
   6:                              + "<image id='1' src='ms-appx:///images/redWide.png' alt='Red image'/>"
   7:                              + "</binding>"
   8:                              + "<binding template='TileSquareImage'>"
   9:                              + "<image id='1' src='ms-appx:///images/graySquare.png' alt='Gray image'/>"
  10:                              + "</binding>"
  11:                              + "</visual>"
  12:                              + "</tile>";
  13:  
  14:            // create a DOM
  15:            Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument();
  16:            // load the xml string into the DOM, catching any invalid xml characters 
  17:            tileDOM.LoadXml(tileXmlString);
  18:  
  19:            // create a tile notification
  20:            TileNotification tile = new TileNotification(tileDOM);
  21:  
  22:            // send the notification to the app's application tile
  23:            TileUpdateManager.CreateTileUpdaterForApplication().Update(tile);

这里比较值得一提的是微软封装好的类库:NotificationsExtensions.rar  下面的2个示例都用到了它,大家可以好好研究下,学习微软是怎么封装类库的

Apptilesandbadgessample.rar

Toastnotificationssample.rar

原文地址:https://www.cnblogs.com/cracker/p/windows8_Notification.html