Windows 10 – Universal Windows Platform – Tile Output

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.

2015-visual-studio

Step 2

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

2015-file-new-project

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.

2015-new-project

Step 4

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

2015-project-add-new-item

Step 5

From the Add New Item window select Visual C# from Installed and select Code 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

2015-add-new-item-library

Step 6

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

using System;
using System.Linq;
using System.Text;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml.Controls;

public class Item
{
    public string Id { get; set; }
    public string Content { get; set; }
    public string Time { get; set; }
}

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

    public void Add(ref ListBox display, string value, TimeSpan occurs)
    {
        DateTime when = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
            occurs.Hours, occurs.Minutes, occurs.Seconds);
        if (when > DateTime.Now)
        {
            StringBuilder template = new StringBuilder();
            template.Append("<tile><visual version=\"4\">");
            template.Append("<binding template=\"TileSquare150x150Text03\">");
            template.AppendFormat("<text id=\"1\">{0}</text>", value);
            template.AppendFormat("<text id=\"2\">{0}</text>", when.ToLocalTime().ToString("HH:mm"));
            template.Append("</binding></visual></tile>");
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(template.ToString());

            ScheduledTileNotification tile = new ScheduledTileNotification(xml, when);
            tile.Id = random.Next(1, 100000000).ToString();
            TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(tile);
            display.Items.Add(new Item { Id = tile.Id, Content = value, Time = when.ToString() });
        }
    }

    public void Remove(ListBox display)
    {
        if (display.SelectedIndex > -1)
        {
            TileUpdateManager.CreateTileUpdaterForApplication().GetScheduledTileNotifications().Where(
                p => p.Id.Equals(((Item)display.SelectedItem).Id)).SingleOrDefault();
            display.Items.RemoveAt(display.SelectedIndex);
        }
    }
}

It should then appear as such:

2015-tile-output-library

Step 7

From the Solution Explorer select MainPage.xaml

2015-mainpage-library

Step 8

Select from the Menu, View then Designer

2015-view-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:

<Page.BottomAppBar>
	<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"/>
		</StackPanel>
	</AppBar>
</Page.BottomAppBar>

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

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="Auto"/>
		<RowDefinition Height="*"/>
	</Grid.RowDefinitions>
	<StackPanel Grid.Row="0">
		<TextBox Margin="10" HorizontalAlignment="Stretch" Name="Value"/>
		<TimePicker Margin="10" HorizontalAlignment="Stretch" Name="Occurs"/>
	</StackPanel>
	<ListBox Name="Display" Grid.Row="1">
		<ListBox.ItemTemplate>
			<DataTemplate>
				<StackPanel>
					<TextBlock TextWrapping="Wrap" Text="{Binding Path=Content}"/>
					<TextBlock Text="{Binding Path=Time}"/>
				</StackPanel>
			</DataTemplate>
		</ListBox.ItemTemplate>
	</ListBox>
</Grid>

It should appear as such:

2015-tile-output-mainpage-xaml

Step 10

Select from the Menu, View then Code

2015-view-code

Step 11

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

public Library Library = new Library();

private void Add_Click(object sender, RoutedEventArgs e)
{
	Library.Add(ref Display, Value.Text, Occurs.Time);
}

private void Remove_Click(object sender, RoutedEventArgs e)
{
	Library.Remove(Display);
}

It should then appear as such:

2015-tile-output-mainpage-code

Step 12

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

2015-local-machine

Step 13

Once the Local Machine has started the Application should then appear

2015-tile-output-local-machine-run

Step 14

After the Application has started you can then type some text then select a Time, then select Add to schedule a Tile Notification for that Time with the Text selected, then select the Start button to show the Start Menu then find the app under “Recently Added” then tap and hold or right-click and select Pin to Start then once done wait for the Notification to appear at the time selected on the Tile for the Application

2015-tile-output-local-machine-ran

Step 15

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

2015-stop

Step 16

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

2015-emulator

Step 17

Once the Emulator has started the Application should then appear

2015-tile-output-emulator-run

Step 18

After the Application has started you can then type some text then select a Time, then select Add to schedule a Tile Notification for that Time with the Text selected, then select the Start button and choose All apps then find the app under “Recently Added” then tap and hold or right-click and select Pin to Start then once done wait for the Notification to appear at the time selected on the Tile for the Application

2015-tile-output-emulator-ran

Step 19

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

2015-stop

Creative Commons License

Advertisements

One thought on “Windows 10 – Universal Windows Platform – Tile Output

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 )

Google+ photo

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

Connecting to %s