Oki Wan BenObi
Oki Wan BenObi

Reputation: 21

WP 8.1 Update Square AND Wide Tile - How?

How do I update both, the square and the wide tile per code at once? Or how can I determine, wich tile type is "loaded" on the start screen?

I have this code:

private void JamesBond()
{
        var tileXML = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text01);
        var tileText = tileXML.GetElementsByTagName("text");
        (tileText[0] as XmlElement).InnerText = "First text";
        (tileText[1] as XmlElement).InnerText = "Second text";
        (tileText[2] as XmlElement).InnerText = "Third text";
        (tileText[3] as XmlElement).InnerText = "Last text";
        var tileNotification = new TileNotification(tileXML);

        var tileXMLw = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text01);
        var tileTextw = tileXMLw.GetElementsByTagName("text");
        (tileTextw[0] as XmlElement).InnerText = "Wide First text";
        (tileTextw[1] as XmlElement).InnerText = "Wide Second text";
        (tileTextw[2] as XmlElement).InnerText = "Wide Third text";
        (tileTextw[3] as XmlElement).InnerText = "Wide Last text";
        var tileNotificationW = new TileNotification(tileXMLw);

        TileUpdateManager.CreateTileUpdaterForApplication().Clear();
        TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
        TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotificationW);
    }
}

...and what it does is, it updates the wide tile. But if it is the square tile, then it updates it.....sometimes. And most of the time, it's empty. So, somehow it works. But not right....

Can anyone help me here?

PS: I also tried to get the TileUpdater instance and do that all in the same instance..that's even worse, it only shows the wide tile...

Thanks in advance.

Regards, ben0bi

Upvotes: 1

Views: 476

Answers (1)

Oki Wan BenObi
Oki Wan BenObi

Reputation: 21

Solved it. According to MSDN, we have to merge the two xml, so that they appear under the same "visual" tag.

I did it like this:

        string xml="<tile>\n";
        xml += "<visual version=\"2\">\n";
        xml += "  <binding template=\"TileSquare150x150Text01\" fallback=\"TileSquareText01\">\n";
        xml += "      <text id=\"1\">Row 0</text>\n";
        xml += "      <text id=\"2\">Row 1</text>\n";
        xml += "      <text id=\"3\">Row 2</text>\n";
        xml += "      <text id=\"4\">Row 3</text>\n";
        xml += "  </binding>\n";
        xml += "  <binding template=\"TileWide310x150Text01\" fallback=\"TileWideText01\">\n";
        xml += "      <text id=\"1\">Wide Row 0</text>\n";
        xml += "      <text id=\"2\">Wide Row 1</text>\n";
        xml += "      <text id=\"3\">Wide Row 2</text>\n";
        xml += "      <text id=\"4\">Wide Row 3</text>\n";
        xml += "  </binding>\n";
        xml+="</visual>\n";
        xml +="</tile>";
        XmlDocument txml = new XmlDocument();
        txml.LoadXml(xml);
        TileNotification tNotification = new TileNotification(txml);

        TileUpdateManager.CreateTileUpdaterForApplication().Clear();
        TileUpdateManager.CreateTileUpdaterForApplication().Update(tNotification);

Upvotes: 1

Related Questions