Windows Phone 8.1 Tiles, Notifications and Action Center

2020-12-13 02:23

阅读:311

标签:c   style   class   blog   code   java   

(1)Tiles

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

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

soscw.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>
soscw.com,搜素材

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

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

soscw.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 = "" +
                           "" +
                              "" +
                                  "" + middlePath + "\" alt=\"alt text\"/>" +
                                  "" +
                                "" +
                                "" +
                                  "" + widePath + "\" alt=\"alt text\"/>" +
                                  "" +
                              "" +
                           "" +
                       "";
    XmlDocument tileXML = new XmlDocument();
    tileXML.LoadXml(tileString);

    TileNotification newTile = new TileNotification(tileXML);
    TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();
    updater.EnableNotificationQueue(false);
    updater.Update(newTile);
}
soscw.com,搜素材

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

soscw.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();
}
soscw.com,搜素材

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

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

 

(2)Notifications

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

soscw.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 方法为:

soscw.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;
}
soscw.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,搜素材,soscw.com

Windows Phone 8.1 Tiles, Notifications and Action Center

标签:c   style   class   blog   code   java   

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


评论


亲,登录后才可以留言!