uwpwindows-10windows-10-mobilelive-tile

Update Live Tile depending on tile size pinned by user


I am facing a problem with Live Tiles in my UWP application. Microsoft provides different templates (MSDN) for different tile sizes to set the content but it also depends on the device how the content is displayed.

For example the wide tile can show more characters on a mobile device than on a desktop computer in a single row, but I want to use the most of the tile area for information display. Let's say the user has installed my app on a desktop computer and he has pinned the big square tile to his start menu. How can I detect the tile size to load the appropriate template? Basically I just want to use a different template depending on the tile the user has pinned (and then I want to handle the filling of the content depending on the used device, but I got that already covered).

Currently I am just using a wide template that does nothing if the user has pinned any other size than the wide one. If the user pinns the wide tile, it works. But I am struggling to find a generic solution for this issue. I'm using SheduledTileNotifications because my app only uses local data for the tile contents.

This is my code to update a tile with a given template:

public static void UpdatePrimaryTile(XmlDocument tileTemplate)
{
    var dt = DateTime.Now.AddSeconds(5);
    dt = DateTime.SpecifyKind(dt, DateTimeKind.Unspecified);
    var not = new ScheduledTileNotification(tileTemplate, new DateTimeOffset(dt, TimeZoneInfo.Local.BaseUtcOffset));
    var tu = TileUpdateManager.CreateTileUpdaterForApplication();
    tu.EnableNotificationQueue(true);
    tu.Clear();
    tu.AddToSchedule(not);
}

Solution

  • You should include all tile sizes in your tileTemplate, not just the wide tile. That way whatever the user chooses will have an appropriate tile to show.

    Just showing the currently chosen tile template isn't sufficient since the user could change it after your notification fired.

    If you look at the adaptive tile documentation at https://learn.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-create-adaptive-tiles it says:

    For a single tile notification XML payload, provide elements for each tile size that you'd like to support, as shown in this example:

    <tile>
      <visual>
    
        <binding template="TileSmall">
          <text>Small</text>
        </binding>
    
        <binding template="TileMedium">
          <text>Medium</text>
        </binding>
    
        <binding template="TileWide">
          <text>Wide</text>
        </binding>
    
        <binding template="TileLarge">
          <text>Large</text>
        </binding>
    
      </visual>
    </tile>
    

    The same applies to the Windows 8.1 templates as shown in Quickstart: Sending a tile update (XAML)

    The user can resize your tile on the Start screen at any time, and there is no way for you to know which state (small, medium, wide, or large) the tile is in when you send a notification.