Cheeky Taurus Studios

Transparent Tiles & User Choice

By on Jul 3, 2014 in Code | 0 comments

One of the things I wanted to make sure and do was provide #Hashtastic users WP8.1 Start Screen compatible transparent tiles, while still giving them the ability to chose the default #Hashtastic background color (red) if they wanted. This functionality was added in #Hashtastic v1.9.

Many thanks to Tim Gabrhel for pointing me toward Andrew Baker’s tutorial. I’ve adapted it to set the desired image so users can toggle using a transparent tile. This works with a WP 8.0 project and should work with a 8.1 SL project, although I haven’t tested that last assumption. I just created a method in App.xaml.cs that uses the setting value for the transparent tile, then call this method inside the Application_Launching event and when the user toggles the setting on or off.

I have two sets of images for each type, one with the “#Hastastic Red” background and one that is transparent, and I store those as content in the project under the Assets folder.

public static void CreateTitles()
	string title = "#Hashtastic";
	string baseUri = "/Assets/Tiles/{0}{1}";
	string fileExt = ApplicationSettings.UseTransparentTile ? "_Transparent.png" : ".png";
	FlipTileData appTile = new FlipTileData();
	appTile.Title = "#Hashtastic";
	appTile.SmallBackgroundImage = new Uri(string.Format(baseUri, "SmallBackgroundImage", fileExt), UriKind.Relative);
	appTile.BackgroundImage = new Uri(string.Format(baseUri, "BackgroundImage", fileExt), UriKind.Relative);
	appTile.BackBackgroundImage = new Uri(string.Format(baseUri, "BackBackgroundImage", fileExt), UriKind.Relative);
	appTile.WideBackgroundImage = new Uri(string.Format(baseUri, "WideBackgroundImage", fileExt), UriKind.Relative);
	appTile.WideBackBackgroundImage = new Uri(string.Format(baseUri, "WideBackBackgroundImage", fileExt), UriKind.Relative);
	appTile.BackContent = string.Empty;
	ShellTile currTile = ShellTile.ActiveTiles.FirstOrDefault();
	if (currTile == null) {
		ShellTile.Create(new Uri(string.Format("/", title), UriKind.Relative), appTile, true);
	} else {

On the design-end of the UI, check out the templates provided by Stan Gursky and Alex Reid over here. It adds a great visual touch to the UI for toggling the tile background.

UPDATE: Chris Field rightly points out half that code is redundant and using First() instead of FirstOrDefault() mean’s you’re asking for an exception if no result is returned. I’ve updated accordingly.