从web源更新平铺图像 - Windows 8应用程序

时间:2013-07-28 10:48:32

标签: c# templates windows-8 windows-store-apps tile

Windows 8应用程序 - metro应用程序 - 您好我想从网络更新平铺图像,但我无法让它工作。我用这个Link 我只进行了一些小的自定义,但网络上的图像不适合我。我有字符串src1中的图像,如果我使用 const字符串src1 =“ms-appx:///Assets/clock24x24.png”; 然后图像工作,但从网络它不工作。有没有人有一些想法?

public static void CreateSchedule()
    {


        var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
        var plannedUpdated = tileUpdater.GetScheduledTileNotifications();
        DateTime now = DateTime.Now;
        DateTime planTill = now.AddHours(4);

        const string src1 = "http://cdn.thenextweb.com/wp-content/blogs.dir/1/files/2012/02/Screen-Shot-2012-02-21-at-4.48.56-PM.png";

        DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0).AddMinutes(1);
        if (plannedUpdated.Count > 0)
            updateTime = plannedUpdated.Select(x => x.DeliveryTime.DateTime).Union(new [] { updateTime }).Max();
        string xml = "<tile>"
                         + "<visual>"
                         + "<binding template='TileWideImageAndText01'>"
                         + "<text id='1'>This tile notification uses web images</text>"
                         + "<image id='1' src='" + src1 + "' alt='Web image'/>"
                         + "</binding>"
                         + "<binding template='TileSquareImage'>"
                         + "<image id='1' src='" + src1 + "' alt='Web image'/>"
                         + "</binding>"
                         + "</visual>"
                         + "</tile>";
        var tileXmlNow = string.Format(xml);
        XmlDocument documentNow = new XmlDocument();
        documentNow.LoadXml(tileXmlNow);

        tileUpdater.Update(new TileNotification(documentNow) { ExpirationTime = now.AddMinutes(1) });

        for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddMinutes(1))
        {
            Debug.WriteLine(startPlanning);
            Debug.WriteLine(planTill);

            try
            {
                var tileXml = string.Format(xml);
                XmlDocument document = new XmlDocument();
                document.LoadXml(tileXml);

                ScheduledTileNotification scheduledNotification = new ScheduledTileNotification(document, new DateTimeOffset(startPlanning)) { ExpirationTime = startPlanning.AddMinutes(1) };
                tileUpdater.AddToSchedule(scheduledNotification);

            }
            catch (Exception e)
            {
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

您是否已激活AppxManifest文件包中的Internet功能?