Updating secondary tile in metro apps


  • I am trying to create and update a secondary tile in my application.

    The code was crashing in the following line:


     Can anyone help me with this??

    auto logo = ref new Uri("ms-appx:///Images/squareTile-sdk.png"); auto wideLogo = ref new Uri("ms-appx:///Images/tile-sdk.png"); Platform::String^ liveTileId = "SecondaryTile.LiveTile"; auto secondaryTile = ref new SecondaryTile(liveTileId, "Live Secondary Tile", //short tile name (will be displayed on the tile) "SDK Sample Live Secondary Tile", // Long tile name (for search, tooltip) "Secondary Tile Pinned argument", // Activation argument Windows::UI::StartScreen::TileOptions::None, logo, wideLogo); secondaryTile->ForegroundText = ForegroundText::Light; FrameworkElement^ element = safe_cast<FrameworkElement^>(sender); Windows::UI::Xaml::Media::GeneralTransform^ buttonTransform = element->TransformToVisual(nullptr); const Point pointOrig(0,0); const Point pointTransformed = buttonTransform->TransformPoint(pointOrig); const Rect rect(pointTransformed.X, pointTransformed.Y, safe_cast<float>(element->ActualWidth), safe_cast<float>(element->ActualHeight)); task<bool>(secondaryTile->RequestCreateForSelectionAsync(rect, Windows::UI::Popups::Placement::Right)).then([this](bool isCreated) { Platform::String^ liveTileId = "SecondaryTile.LiveTile"; auto tileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileWideText04); // Refer to template documentation to determine how many text fields a particular template has // get the text attributes for this template and fill them in auto tileTextElements = tileXml->GetElementsByTagName("text"); tileTextElements->Item(0)->AppendChild(tileXml->CreateTextNode("How r u\n")); auto tileTextElements1 = tileXml->GetElementsByTagName("text"); tileTextElements1->Item(0)->AppendChild(tileXml->CreateTextNode("U there\n")); tileTextElements1->Item(0)->AppendChild(tileXml->CreateTextNode("Text here 1\n")); auto squareTileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquareText04); auto squareTileTextElements = squareTileXml->GetElementsByTagName("text"); squareTileTextElements->Item(0)->AppendChild(squareTileXml->CreateTextNode("Text 2 here")); // Include the square template in the notification auto subNode = tileXml->ImportNode(squareTileXml->GetElementsByTagName("binding")->Item(0), true); tileXml->GetElementsByTagName("visual")->Item(0)->AppendChild(subNode); // Create the notification from the XML auto tileNotification = ref new TileNotification(tileXml); if(Windows::UI::StartScreen::SecondaryTile::Exists(liveTileId)){

    // Send the notification to the secondary tile by creating a secondary tile updater TileUpdateManager::CreateTileUpdaterForSecondaryTile(liveTileId)->Update(tileNotification); } });

    Friday, May 4, 2012 9:49 AM

All replies

  •   Hello,


    Would you please upload the sample project to skydriver, so that we can analyze it deeply.



    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.


    Best regards,


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 7, 2012 11:27 AM