Windows 10 Universal Windows Platform – Tiles

Step 1

Download Visual Studio Community 2015 and install it onto your computer, if it’s already downloaded and installed select Launch to start Visual Studio Community 2015 or if it has already been downloaded and installed then start the application you may also need to Enable your device for development.


Step 2

Once Visual Studio Community 2015 has started select File, then New, then Project… from the Menu.


Step 3

From the New Project window select Visual C# from Installed, Templates then select Blank App (Windows Universal) from the list, then type in a Name and select a Location to save to before selecting Ok to create the Project.


Step 4

Once done select from the Menu, Project, then Add New Item…


Step 5

From the Add New Item window select Visual C# from Installed then select Code File from the list, then type in the Name as Library.cs before selecting Add to add the file to the Project


Step 6

Once in the Code View for Library.cs the following should be entered:

using System;
using System.Collections.Generic;
using System.Globalization;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.StartScreen;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

public class Item
    public string Id { get; set; }
    public string Content { get; set; }
    public Brush Colour { get; set; }

public class Library
    private Random random = new Random((int)DateTime.Now.Ticks);

    private Color stringToColour(string value)
        return Color.FromArgb(
        Byte.Parse(value.Substring(0, 2), NumberStyles.HexNumber),
        Byte.Parse(value.Substring(2, 2), NumberStyles.HexNumber),
        Byte.Parse(value.Substring(4, 2), NumberStyles.HexNumber),
        Byte.Parse(value.Substring(6, 2), NumberStyles.HexNumber));

    public static Rect getElementRect(FrameworkElement element)
        GeneralTransform buttonTransform = element.TransformToVisual(null);
        Point point = buttonTransform.TransformPoint(new Point());
        return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));

    public async void Add(ListBox display, string value, ComboBox colour, object selection)
        string id = random.Next(1, 100000000).ToString();
        SecondaryTile tile = new SecondaryTile(id, value, id, new Uri("ms-appx:///"), TileSize.Default);
        Color background = stringToColour(((ComboBoxItem)colour.SelectedItem).Tag.ToString());
        tile.VisualElements.BackgroundColor = background;
        tile.VisualElements.ForegroundText = ForegroundText.Light;
        tile.VisualElements.ShowNameOnSquare150x150Logo = true;
        tile.VisualElements.ShowNameOnSquare310x310Logo = true;
        tile.VisualElements.ShowNameOnWide310x150Logo = true;
        await tile.RequestCreateForSelectionAsync(getElementRect((FrameworkElement)selection));
        display.Items.Add(new Item { Id = tile.TileId, Content = value, Colour = new SolidColorBrush(background) });

    public async void Remove(ListBox display)
        if (display.SelectedIndex > -1)
            string id = ((Item)display.SelectedItem).Id;

            if (SecondaryTile.Exists(id))
                SecondaryTile tile = new SecondaryTile(id);
                await tile.RequestDeleteAsync();

    public async void List(ListBox display)
        IReadOnlyList<SecondaryTile> list = await SecondaryTile.FindAllAsync();
        foreach (SecondaryTile item in list)
            display.Items.Add(new Item
                Id = item.TileId,
                Content = item.DisplayName,
                Colour = new SolidColorBrush(item.VisualElements.BackgroundColor)

It should then appear as such:


Step 7

From the Solution Explorer select MainPage.xaml


Step 8

Select from the Menu, View then Designer


Step 9

The Design View will be displayed along with the XAML View and in this above <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”> enter the following XAML:

	<AppBar IsOpen="True" IsSticky="True">
		<StackPanel Orientation="Horizontal">
			<AppBarButton Name="Add" Icon="Add" Label="Add" Click="Add_Click"/>
			<AppBarButton Name="Remove" Icon="Remove" Label="Remove" Click="Remove_Click"/>

While still in the XAML View below <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>enter the following XAML:

		<RowDefinition Height="Auto"/>
		<RowDefinition Height="*"/>
	<Grid Grid.Row="0">
			<ColumnDefinition Width="*"/>
			<ColumnDefinition Width="Auto"/>
		<TextBox Grid.Column="0" Margin="20" VerticalAlignment="Center" Name="Value"/>
		<ComboBox Grid.Column="1" Name="Colour" VerticalAlignment="Center" Margin="20">
			<ComboBoxItem Tag="FF000000" IsSelected="True">
				<Rectangle Width="25" Height="14" Fill="Black"/>
			<ComboBoxItem Tag="FF808080">
				<Rectangle Width="25" Height="14" Fill="Gray"/>
			<ComboBoxItem Tag="FFFF0000">
				<Rectangle Width="25" Height="14" Fill="Red"/>
			<ComboBoxItem Tag="FFFFA500">
				<Rectangle Width="25" Height="14" Fill="Orange"/>
			<ComboBoxItem Tag="FFFFFF00">
				<Rectangle Width="25" Height="14" Fill="Yellow"/>
			<ComboBoxItem Tag="FF008000">
				<Rectangle Width="25" Height="14" Fill="Green"/>
			<ComboBoxItem Tag="FF00FFFF">
				<Rectangle Width="25" Height="14" Fill="Cyan"/>
			<ComboBoxItem Tag="FF0000FF">
				<Rectangle Width="25" Height="14" Fill="Blue"/>
			<ComboBoxItem Tag="FFFF00FF">
				<Rectangle Width="25" Height="14" Fill="Magenta"/>
			<ComboBoxItem Tag="FF800080">
				<Rectangle Width="25" Height="14" Fill="Purple"/>
	<ListBox Name="Display" Grid.Row="1">
				<StackPanel Orientation="Horizontal">
					<TextBlock TextWrapping="Wrap" Text="{Binding Path=Content}"/>
					<Rectangle Width="25" Height="14" Margin="5" Fill="{Binding Path=Colour}"/>

It should appear as such:


Step 10

Select from the Menu, View then Code


Step 11

Once in the Code View below the public MainPage() { … } the following should be entered:

Library Library = new Library();

private void Add_Click(object sender, RoutedEventArgs e)
	Library.Add(Display, Value.Text, Colour, sender);

private void Remove_Click(object sender, RoutedEventArgs e)

It should then appear as such:


Step 12

That completes the Windows Universal Application so Save the Project then select the Debug and Local Machine option to run the Application


Step 13

Once the Application has started the following should then appear


Step 14

After the Application has started running if your Local Machine you can then type some text then select a Colour, then select Add to Pin to Start, then select Start button on Local Machine to view the pinned Tile


Step 15

To Exit the application select Stop Debugging in Visual Studio Community 2015


Step 16

Another option is to run as a Windows Phone application, select Debug and select Emulator WVGA 4 inch 512MB option to run the Application


Step 17

Once the Emulator has started the Application should then appear


Step 18

After the Application has started running if the Emulator you can then type some text then select a Colour, then select Add to Pin to Start then select Start button on Emulator to view the pinned Tile


Step 19

To Exit the application select Stop Debugging in Visual Studio Community 2015


Creative Commons License

One thought on “Windows 10 Universal Windows Platform – Tiles

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s