Universal Windows Platform – Tiles

Tiles demonstrates how to Pin SecondaryTile items to the Start Menu of Windows 10

Step 1

If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu find and select Visual Studio 2017.


Step 2

Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…


Step 3

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

Step 4

Then in New Universal Windows Project you need to select the Target Version this should be at least the Windows 10 Fall Creators Update (10.0; Build 16299) and the Minimum Version to be the same.


The Target Version will control what features your application can use in Windows 10 so by picking the most recent version you’ll be able to take advantage of those features. To make sure you always have the most recent version, in Visual Studio 2017 select Tools Extensions and Updates… then and then see if there are any Updates

Step 5

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


Step 6

From the Add New Item window select Visual C#, then Code 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 7

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

using System;
using System.Collections.Generic;
using System.Globalization;
using Windows.UI;
using Windows.UI.StartScreen;
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 FromString(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 async void Init(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)

    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 = FromString(((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.RequestCreateAsync();
        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();

In the Library.cs there are using statements to include the necessary functionality. The Item Class represents a pinned Tile, then in the Library Class the FromString Method converts a string colour into a Color. The Init Method sets the contents of the ListBox to a list of items by using SecondaryTile.FindAllAsync. The Add Method will not only insert an item in to the ListBox but also Pin a SecondaryTile to the Start Menu of Windows 10. Remove will un-pin the Tile and remove the entry from the ListBox.

Step 8

In the Solution Explorer select MainPage.xaml


Step 9

From the Menu choose View and then Designer


Step 10

The Design View will be displayed along with the XAML View and in this between the Grid and /Grid elements, 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}"/>
<CommandBar VerticalAlignment="Bottom">
	<AppBarButton Icon="Add" Label="Add" Click="Add_Click"/>
	<AppBarButton Icon="Remove" Label="Remove" Click="Remove_Click"/>

The first block of XAML the main user interface of the Application, this features a Grid with the first row containing a TextBox where text may be entered to show on a Tile and then there’s a ComboBox where the background colour of the Tile may be selected. The second row contains a ListBox to display the list of tiles or items that have been pinned to Start. The second block of XAML is the CommandBar which contains the Add and Remove options to manage the list.

Step 11

From the Menu choose View and then Code


Step 12

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

Library library = new Library();

protected override void OnNavigatedTo(NavigationEventArgs e)

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

private void Remove_Click(object sender, RoutedEventArgs e)

Below the MainPage() Method an instance of the Library Class is created. The OnNavigatedTo Event handler will call the Init Method in the Library Class. The Add_Click Method will add items to the Start Menu and also to the ListBox and Remove_Click will delete items from the list.

Step 13

That completes the Universal Windows Platform Application so Save the Project then in Visual Studio select the Local Machine to run the Application


Step 14

After the Application has started running you can then type some text then select a Colour, then select Add to Pin to Start, it will ask “Do you want to Pin this tile to Start?”


Step 15

Along with an item being added to the list you can also select Start button on Local Machine of Windows 10 to view the pinned Tile


Step 16

To Exit the Application select the Close button in the top right of the Application


Creative Commons License

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s