I am trying to schedule several messages for update on the tile but the 4th line on the second method tileTextAttributes[0].InnerText = Message; keeps throwing exceptions saying incorrect parameters. Can you help me solve the problem?
private void SetupTiles()
{
try
{
DateTimeOffset time = DateTime.Now;
for (int i = 0; i < messages.Count; i++)
{
Windows.UI.Notifications.ScheduledTileNotification stf = new ScheduledTileNotification(GetTile(messages[i]), time);
time.Add(new TimeSpan(0, 0, 0, 30, 0));
TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(stf);
}
}
catch (Exception ex)
{
new Windows.UI.Popups.MessageDialog(ex.Message).ShowAsync();
}
}
XmlDocument GetTile(string Message)
{
XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText05);
string t = tileXml.ToString();
XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
tileTextAttributes[0].InnerText = Message;
XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04);
XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode(Message));
IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);
return tileXml;
}
Edit
System.ArgumentException: The parameter is incorrect.
at
Windows.UI.Notifications.ScheduledTileNotification..ctor(XmlDocument
content, DateTimeOffset deliveryTime)
at
TestProj.MainPage.SetupTiles() in c:\Users\ddds\Documents\Visual
Studio 2012\Projects\TestProj\TestProj\MainPage.xaml.cs:line 398
The XML seems fine to me, but you’re scheduling the notification for a moment that has just passed. Add the time offset BEFORE the constructor.
EDIT
Looks like it’s a bit more subtle than that, I think perhaps because how the various time functions work vis-à-vis UTC. For example,
is ok, but not:
I have some info in my blog post on Scheduled Notifications that might help.