Windows Phone 十四、磁贴通知

磁贴(Tile)

Windows Phone 磁贴种类:

小尺寸

SmallLogo:71x71;

Square71x71

中等

Logo:150x150;

Square150x150

WideLogo:300x150;

Wide310x150

 1     <StackPanel>
 2         <Button
 3             Content="创建磁贴"
 4             Click="Button_Click"/>
 5         <Button
 6             Content="获取磁贴"
 7             Click="Button_Click_1"/>
 8         <Button
 9             Content="创建通知"
10             Click="Button_Click_2"/>
11     </StackPanel>
 1         private async void Button_Click(object sender, RoutedEventArgs e)
 2         {
 3             //创建磁贴对象
 4             SecondaryTile tile = new SecondaryTile(
 5                 "my_tile",//new Random().Next().ToString(),
 6                 "测试标签",
 7                 string.Format("actived@{0:yyyy-MM-dd HH:mm}", DateTime.Now),//为Onlaunced传递参数
 8                 new Uri("ms-appx:///Assets/StoreLogo.scale-240.png"),// ms-appx:/// 应用程序根目录
 9                 TileSize.Wide310x150);//尺寸
10             //当磁贴设置为宽时一定要设置该属性(小尺寸一样)
11             tile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/StoreLogo.scale-240.png");
12             //设置磁贴参数
13             tile.VisualElements.ShowNameOnSquare150x150Logo = true;
14             //展示
15             bool isShow = await tile.RequestCreateAsync();
16             if (!isShow)
17             {
18                 await new Windows.UI.Popups.MessageDialog("展示失败").ShowAsync();
19             }
20         }
21 
22         private async void Button_Click_1(object sender, RoutedEventArgs e)
23         {
24             //if (SecondaryTile.Exists("my_tile"))
25             //{
26             //    //表示存在该磁贴
27             //    var tile = new SecondaryTile("my_tile");
28             //    tile.VisualElements.Square71x71Logo = new Uri("ms-appx:///Assets/1.png");
29             //    tile.DisplayName = DateTime.Now.ToString();
30             //    var show = tile.VisualElements.ShowNameOnSquare150x150Logo;
31             //    await tile.UpdateAsync();
32             //}
33             var list = await SecondaryTile.FindAllForPackageAsync();
34             foreach (var item in list)
35             {
36                 //无法直接编辑ITEM对象
37                 var tile = new SecondaryTile(item.TileId);
38                 tile.VisualElements.Square71x71Logo = new Uri("ms-appx:///Assets/1.png");
39                 tile.DisplayName = DateTime.Now.ToString();
40                 var show = tile.VisualElements.ShowNameOnSquare150x150Logo;
41                 await tile.UpdateAsync();
42             }
43         }
44 
45         private void Button_Click_2(object sender, RoutedEventArgs e)
46         {
47             var tileTmpl = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageCollection);
48             var imageNodes = tileTmpl.GetElementsByTagName("image");
49             for (int i = 0; i < 5; i++)
50             {
51                 imageNodes[i].Attributes[1].NodeValue = "Assets/" + (i + 1) + ".png";
52             }
53             //var node1 = tileTmpl.GetElementsByTagName("text").FirstOrDefault();
54             //node1.InnerText = "Hello";
55             //var node2 = tileTmpl.GetElementsByTagName("text").LastOrDefault();
56             //node2.InnerText = "World";
57             TileNotification tileNotification = new TileNotification(tileTmpl);
58             TileUpdateManager.CreateTileUpdaterForSecondaryTile("my_tile").Update(tileNotification);
59         }
原文地址:https://www.cnblogs.com/includeling/p/4594430.html