locked
Tile Notifications from C# RRS feed

  • Question

  • Has anyone tried doing tile notifications from C#? I tried converting part of the Javascript Basic Tiles Sample to C#, and although the code runs with no errors, the notifications don't appear on the tile.
    Saturday, September 17, 2011 1:23 AM

Answers

  • I was able to make it work using this little piece of code, could you try it? (Not exactly best practices)
    public void Notify(string text)
    {
        var xmlDocument = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText01);
        var textNode = xmlDocument.GetElementsByTagName("text").First();
        var newText = xmlDocument.CreateTextNode(text);
        textNode.AppendChild(newText);
        var tileNotification = new TileNotification(xmlDocument);
        var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
        tileUpdater.Update(tileNotification);
    }
    

    Saturday, September 17, 2011 5:08 PM

All replies

  • I was able to make it work using this little piece of code, could you try it? (Not exactly best practices)
    public void Notify(string text)
    {
        var xmlDocument = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText01);
        var textNode = xmlDocument.GetElementsByTagName("text").First();
        var newText = xmlDocument.CreateTextNode(text);
        textNode.AppendChild(newText);
        var tileNotification = new TileNotification(xmlDocument);
        var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
        tileUpdater.Update(tileNotification);
    }
    

    Saturday, September 17, 2011 5:08 PM
  • That worked. I was doing basically the same thing, not sure why it didn't work.

     

    What about this isn't a "best practice"?

    Sunday, September 18, 2011 11:47 AM
  • The way the XML node is selected is a little hackish in my opinion.

    I think you should use the SelectSingleNode method of the XmlDocument instead of GetElementsByTagName:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.data.xml.dom.xmldocument.selectsinglenode%28v=VS.85%29.aspx

     

    Anyhow, it has been proposed to change the way the notification system works to not use XML, but a strongly-typed approach here:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/5c7aa8ef-10da-4b01-b260-581f7faaa3e1

    And I hope it is going to happen. Using XML to communicate in code is wrong.

    Sunday, September 18, 2011 12:53 PM
  • One of the first batch of Windows Updates for the developer preview is to resolve some issues with tile notifications not happening when they should (you can actually see this bug in the Build presentation on Tiles and Notifications) so it might be you were just hitting that bug rather than doing anything wrong. The joys of pre-beta software. ;-)
    Sunday, September 18, 2011 3:33 PM