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.
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);
}
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With