Mango Application Tile - remove back
Asked Answered
W

3

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.

Wraparound answered 4/7, 2011 at 16:9 Comment(2)
how are you trying to remove it?Godfearing
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.Wraparound
W
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);
}
Wraparound answered 7/7, 2011 at 11:37 Comment(1)
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).Cantrip
O
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);
        }
Outstrip answered 16/1, 2012 at 18:47 Comment(0)
G
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());
Godfearing answered 5/7, 2011 at 16:38 Comment(3)
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. :(Wraparound
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?Wraparound
Matt Lacey - No, neither of them do, I'm afraid. Thanks for trying.Wraparound

© 2022 - 2024 — McMap. All rights reserved.