20

This is a simple question, and a seemingly simple task but I can't find any info on how to accomplish what I need to do.

I have an application whose main tile (when pinned) sometimes needs to be the default, single sided tile and sometimes needs to have information displayed on the back of the tile. I can add the BackBackgroundImage, BackContent and BackTitle successfully from the ScheduledActionService, but I can't remove them when they are no longer required. This isn't a secondary tile so I can't remove it and re-create and re-add it.

Does anyone know if it is possible to revert a double-sided tile back to single-sided via code, and if so, how can I achieve that behaviour, please?

EDIT

The settings that get applied from the StandardTileData object are additive - if you only specify a title, for example, all other elements remain the same and only the title is updated. I have attempted to set the three parameters that appear on the back of the tile to null and had partial success. The effect is that the background image, title text and content text are all removed, but the tile still flips over to show a completely empty reverse side.

EDIT AGAIN

So, looking at the documentation, the tile back behaves differently to the front. Setting the back content or backtitle to string.Empty will remove those. All good there. However, it does say that "If set to an empty URI, the BackBackgroundImage will not be displayed.". How do I go about creating an empty Uri? I tried new Uri(string,Empty) but that throws an exception about trying to create an empty Uri - which is what I'm trying to do.

Todd Main
  • 31,359
  • 10
  • 76
  • 141
ZombieSheep
  • 28,629
  • 10
  • 64
  • 112
  • how are you trying to remove it? – Matt Lacey Jul 05 '11 at 10:45
  • I've tried setting the three "Back" properties to nulls (didn't work), empty strings/URIs (didn't work). I have also tried creating 2 StandardTileData objects (one for single sided, 1 for double sided) and applying them as appropriate, but that also failed. – ZombieSheep Jul 05 '11 at 11:12

3 Answers3

28

OK, I think I've got it, and it appears to be related to a change in the way tile data is handled...

Previously, setting a value to an empty string would have now effect in the tile. For eaxmple, setting title = string.Empty would leave the existing title in place. Now, though, it will blank out the title. That's good - it means I can remove BackTitle and BackContent string easily. We're half way there.

Now, to get rid of the BackBackgroundImage, the documentation states "If set to an empty URI, the BackBackgroundImage will not be displayed." - all good, except you can't create an empty Uri in any simple way. The one way I've made it work is to set it to a Uri value that doesn't exist, eg

BackBackgroundImage = new Uri("obviouslyMadeUpLocation", UriKind.Relative);

I would have expected that to throw an exception when you try to apply it to the tile, but it doesn't - it just clears the background image.

So that's it. All I appear to need to do is to call the following to unset these properties and put my tile back as it was.

private void ResetMyMainTile()
{
    ShellTile tile = ShellTile.ActiveTiles.First();
    StandardTileData data = new StandardTileData
    {
        BackBackgroundImage = new Uri("IDontExist",UriKind.Relative),
        BackContent = string.Empty,
        BackTitle = string.Empty
    };
    tile.Update(data);
}
ZombieSheep
  • 28,629
  • 10
  • 64
  • 112
  • 2
    You can create an empty Uri like this: `new Uri("", UriKind.Relative)` (note that if you specify UriKind as Absolute, it'll throw an exception). – hasseg Sep 11 '11 at 22:00
1

This one works for me.

new Uri("Background.png", UriKind.RelativeOrAbsolute);

ShellTile TileToFind = ShellTile.ActiveTiles.First();

        if (TileToFind != null)
        {

            StandardTileData NewTileData = new StandardTileData
            {
                Title ="Status",
                BackgroundImage = new Uri("Background.png", UriKind.RelativeOrAbsolute),
                Count = 0,
                BackTitle = "",
                BackBackgroundImage = new Uri("doesntexist.png", UriKind.RelativeOrAbsolute),
                BackContent = ""
            };

            TileToFind.Update(NewTileData);
        }
shanethehat
  • 15,105
  • 10
  • 54
  • 84
winappdev
  • 11
  • 1
0

Try setting the whole tile (all details) again to everything as was before / is now but without the background details.

Update
Does this not work?:

ShellTile tile = ShellTile.ActiveTiles.First();
tile.Update(null);

or

tile.update(new StandardTileData());
Matt Lacey
  • 64,328
  • 10
  • 87
  • 143
  • 1
    Thanks for the suggestion, Matt, but these settings are additive - if you omit one of the parameters, the previous value of the parameter persists (e.g. just setting the tile title will leave all other bits of the tile intact). That's why I thought setting them to null would do the trick, and it partially does - it removes the visible elements from the back of the tile, but the back still gets displayed as an empty tile. :( – ZombieSheep Jul 05 '11 at 22:25
  • I've updated my question based on the documentation. I'm now stuck attempting to create an "empty Uri" for the background image. Any suggestion on that, please? – ZombieSheep Jul 07 '11 at 11:24
  • Matt Lacey - No, neither of them do, I'm afraid. Thanks for trying. – ZombieSheep Jul 07 '11 at 12:39