个人资料

跳过导航链接首页 > 博客列表 > 博客正文

UWP使用动态磁贴

:

动态磁贴样式1

   public static void SetupTileAlert(string f,string s,string b)
        {
            // In a real app, these would be initialized with actual data
            string from = f;
            string subject = s;
            string body = b;
            // TODO - all values need to be XML escaped
            // Construct the tile content as a string
            string content = $@"
<tile>
    <visual>
        <binding template='TileMedium'>
            <text>{from}</text>
            <text hint-style='captionSubtle'>{subject}</text>
            <text hint-style='captionSubtle'>{body}</text>
        </binding>
 
        <binding template='TileWide'>
            <text hint-style='subtitle'>{from}</text>
            <text hint-style='captionSubtle'>{subject}</text>
            <text hint-style='captionSubtle'>{body}</text>
        </binding>
    </visual>
</tile>";
            // Load the string into an XmlDocument
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(content);
            // Then create the tile notification
            var notification = new TileNotification(doc);
            notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10);
            TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
            if (SecondaryTile.Exists("MySecondaryTile"))
            {
                // Get its updater
                var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile("MySecondaryTile");
                // And send the notification
                updater.Update(notification);
            }
        }

动态磁贴样式2

 public async void SetupTileAlert2()
        {
            string imgurl = "ms-appx:///images/bg2.jpg";
            string title ="提醒";
            string description ="接下来需要参加";
            string content = $@"
<tile branding='name'> 
  <visual version='3'>
    <binding template='TileMedium'>
      <image src='{imgurl}' placement='peek'/>
      <text>{title}</text>
      <text hint-style='captionsubtle' hint-wrap='true'>{description}</text>
    </binding>
    <binding template='TileWide'>
      <image src='{imgurl}' placement='peek'/>
      <text>{title}</text>
      <text hint-style='captionsubtle' hint-wrap='true'>{description}</text>
    </binding>
    <binding template='TileLarge'>
      <image src='{imgurl}' placement='peek'/>
      <text>{title}</text>
      <text hint-style='captionsubtle' hint-wrap='true'>{description}</text>
    </binding>
  </visual>
</tile>";
            // Load the string into an XmlDocument
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(content);
            // Then create the tile notification
            var notification = new TileNotification(doc);
            notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10);
            TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
 
            if (SecondaryTile.Exists("MySecondaryTile"))
            {
                // Get its updater
                var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile("MySecondaryTile");
                // And send the notification
                updater.Update(notification);
            }
 
        }

(the end)

songshizhao
最初发表2017/12/5 23:31:54 最近更新2017/12/5 23:31:54 3631
为此篇作品打分
10