Windows 8 应用程序 - Metro 应用程序 - 您好,我想从 Web 更新磁贴图像,但我无法让它工作。我使用这个链接 我只做了一些小的定制,但来自网络的图像对我不起作用。我在字符串 src1 中有图像,如果我使用const string 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)
{
}
}
}