locked
What happens with the tile's pictures?!

    Question

  • I change tile picture in the background task (both square and wide).

    But this pictures are not changed sometimes, are not showed sometimes. Or they are showed but if I change size of the tile (i.e. from Wide to Medium) then default picture is reverted. Wide and Medium sizes are changed at least sometimes, but Small size is not changed absolutely!!!  

    How does it work?!

    Some working code (sometimes working):

    using Windows.UI.Notifications;
    using Windows.Data.Xml.Dom;
    
    namespace BackGroundTask
    {
        public enum ImageColor { black, red, green, blue };
    
        
        // TileNotification
        public sealed class Tiles
        {
            enum ImageSizeTypes { SquareImage, WideImage };
    
            //send tile notifications
            public static void sendTileNotification(ImageColor color)
            {
    
                NetworkInfo networkInfo = NetworkInfo.getInstance();
                sendTileNotificationDueToImageSize(color, ImageSizeTypes.SquareImage);
                sendTileNotificationDueToImageSize(color, ImageSizeTypes.WideImage);
            }
    
            //send tile notification for one size
            private static void sendTileNotificationDueToImageSize(ImageColor color, ImageSizeTypes imageSize)
            {
                // Create a tile update manager for the specified syndication feed.
                var updater = TileUpdateManager.CreateTileUpdaterForApplication();
                updater.EnableNotificationQueue(true);
                updater.Clear();
    
                XmlDocument tileXml;
                string imageDir;
                switch (imageSize)
                {
                    case ImageSizeTypes.SquareImage:
                        tileXml = Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(Windows.UI.Notifications.TileTemplateType.TileSquareImage);
                        imageDir = "squareTiles";
                        break;
                    case ImageSizeTypes.WideImage:
                        tileXml = Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(Windows.UI.Notifications.TileTemplateType.TileWideImage);
                        imageDir = "wideTiles";
                        break;
                    default:
                        return;
                }
    
    
                XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
    
                //turn of branding
                //it hides small icon in the right bottom corner of the tile
                XmlNodeList tileBindings = tileXml.GetElementsByTagName("binding");
                ((XmlElement)tileBindings[0]).SetAttribute("branding", "none");
    
                switch (color)
                {
                    case ImageColor.black:
                        ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "/images/" + imageDir + "/tileBlack.png");
                        break;
                    case ImageColor.red:
                        ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "/images/" + imageDir + "/tileRed.png");
                        break;
                    case ImageColor.green:
                        ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "/images/" + imageDir + "/tileGreen.png");
                        break;
                    case ImageColor.blue:
                        ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "/images/" + imageDir + "/tileBlue.png");
                        break;
    
                    default:
                        return;
                }
    
                // Create a new tile notification. 
                updater.Update(new Windows.UI.Notifications.TileNotification(tileXml));
            }
    
            
    
        }
    }

     
    • Edited by _dima Friday, March 7, 2014 11:32 PM
    Friday, March 7, 2014 11:32 PM

Answers

All replies

  • You need to include all tile sizes that you support in each tile update. That way if the user changes the tile size there is a tile to show. See the Include both a square and wide notification in the payload section in the Quickstart: Sending a tile update

    Also see Troubleshooting tile, toast, and badge notifications

    --Rob

    • Marked as answer by _dima Saturday, March 8, 2014 2:09 AM
    Saturday, March 8, 2014 1:58 AM
    Owner
  • Thank you very much for useful links.

    I've read them and I'm a little confused... There are a lot of terms(secondary tiles, queue of notifications, toast, badges and etc.) but examples are very small. 

    So now I'm trying to implement following solution:

    - there is some event when tile must be updated

    - when the event is occurred I send notification (like in the example bellow)

    and I want that tile is set to the corresponding picture and it is not changed until I send new notification.

    The tile has to have only established (by notification) picture without badges and texts etc.

    But there are problems:

    1. When event is occurred, tile picture is changed (i.e, red picture is set) and I open any other program  and come back to the start panel:

    tile has default picture (it's green) and after second it is changed to the red picture

    I want no changing to the default picture absolutely if I've set any other picture. Is it possible?

    2. Small picture is not changed absolutely. Medium picture is changed, wide picture is changed but small is not. Why? 

    using NotificationsExtensions.TileContent;

    public sealed class Tiles { private static int index_ = 0; private static string[] pictureList_ = {"tileGrey.png","tileRed.png","tileBlue.png","tileGreen.png"}; //test notification public static void testNotification() { string pictureName = pictureList_[index_]; ITileWideImage wideImageContent = TileContentFactory.CreateTileWideImage(); wideImageContent.Branding = TileBranding.None; wideImageContent.Image.Src = "ms-appx:///images/wideTiles/" + pictureName; wideImageContent.Image.Alt = ""; ITileSquareImage squareContent = TileContentFactory.CreateTileSquareImage(); squareContent.Branding = TileBranding.None; squareContent.Image.Src = "ms-appx:///images/squareTiles/" + pictureName; squareContent.Image.Alt = ""; wideImageContent.SquareContent = squareContent; //TileUpdateManager.CreateTileUpdaterForApplication().Update(wideImageContent.CreateNotification()); // Create a tile update manager for the specified syndication feed. TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.Clear(); updater.EnableNotificationQueue(true); updater.StopPeriodicUpdate(); //send tile notification updater.Update(wideImageContent.CreateNotification()); index_ = index_ + 1; if (index_ > 3) index_ = 0; } }



    • Edited by _dima Monday, March 10, 2014 2:45 PM
    Monday, March 10, 2014 2:44 PM