码迷,mamicode.com
首页 > Windows程序 > 详细

Windows Phone 8.1 Tiles, Notifications and Action Center

时间:2014-06-04 17:10:07      阅读:418      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

(1)Tiles

Tiles 也就是磁贴,是 Windows Phone 的一大特色。

一个 Tile 其实可以看成是一个 XML,比如:

bubuko.com,布布扣
<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>
bubuko.com,布布扣

微软为我们提供了一系列模板,具体可参照:链接

只要根据模板的 XML 格式,便可轻松的更新 Tile:

bubuko.com,布布扣
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);
}
bubuko.com,布布扣

除了主磁贴外我们还可以新建 SecondaryTile:

bubuko.com,布布扣
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();
}
bubuko.com,布布扣

SecondaryTile 的更新与主磁贴更新一样:

TileUpdater update = TileUpdateManager.CreateTileUpdaterForSecondaryTile("Cortana");

 

(2)Notifications

Notification(推送通知)分为 Tile,Badge,Toast,Raw 四种类型,而通知的方式又分为 Scheduled,Periodic,Local,Push 四种,它们之间对应的关系为:

bubuko.com,布布扣

使用方法都大同小异,根据各自的 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 方法为:

bubuko.com,布布扣
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;
}
bubuko.com,布布扣

 

(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");

 

Windows Phone 8.1 Tiles, Notifications and Action Center,布布扣,bubuko.com

Windows Phone 8.1 Tiles, Notifications and Action Center

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/xiaoshi3003/p/3764507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!