Windows 10 – Universal Windows Platform – Toast Input

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.Text;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;

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

    public void Schedule(DateTime when)
    {
        StringBuilder template = new StringBuilder();
        template.Append("<toast><visual version='2'><binding template='ToastText02'>");
        template.AppendFormat("<text id='2'>Enter Message:</text>");
        template.Append("</binding></visual><actions>");
        template.Append("<input id='message' type='text'/>");
        template.Append("<action activationType='foreground' content='ok' arguments='ok'/>");
        template.Append("</actions></toast>");
        XmlDocument xml = new XmlDocument();
        xml.LoadXml(template.ToString());
        ScheduledToastNotification toast = new ScheduledToastNotification(xml, when);
        toast.Id = random.Next(1, 100000000).ToString();
        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
    }
}

It should then appear as such:

2015-toast-input-library

Step 7

From the Solution Explorer select App.xaml

2015-app-library

Step 8

Select from the Menu, View then Code

2015-view-code

Step 9

Once in the Code View for App.xaml.cs the following event handler should be entered below private void OnSuspending(object sender, SuspendingEventArgs e) { … }:

protected async override void OnActivated(IActivatedEventArgs e)
{
	base.OnActivated(e);
	try
	{
		if (e.Kind == ActivationKind.ToastNotification)
		{
			ToastNotificationActivatedEventArgs toastArgs = (ToastNotificationActivatedEventArgs)e;
			await new Windows.UI.Popups.MessageDialog((string)toastArgs.UserInput["message"]).ShowAsync();
		}
	}
	catch { }
}

It should then appear as such:

2015-toast-input-app-code

Step 10

From the Solution Explorer select MainPage.xaml

2015-mainpage-library

Step 11

Select from the Menu, View then Designer

2015-view-designer

Step 12

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

<Button Content="Display" Click="Button_Click" HorizontalAlignment="Center"/>

It should appear as such:

2015-toast-input-mainpage-xaml

Step 13

Select from the Menu, View then Code

2015-view-code

Step 14

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

public Library Library = new Library();

private void Button_Click(object sender, RoutedEventArgs e)
{
	Library.Schedule(DateTime.Now + TimeSpan.FromMinutes(1));
}

It should then appear as such:

2015-toast-input-mainpage-code

Step 15

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 16

Once the Local Machine has started the Application should then appear

2015-toast-input-local-run

Step 17

After the Application has started running you can then tap Display then after a minute a Toast Notification will be displayed that can be used to enter text to show message in the Application

2015-toast-input-local-ran

Step 18

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

2015-stop

Step 19

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 20

Once the Emulator has started the Application should then appear

2015-toast-input-emulator-run

Step 21

After the Application has started running you can then tap Display then after a minute a Toast Notification will be displayed that can be used to enter text to show message in the Application

2015-toast-input-emulator-ran

Step 22

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

2015-stop

Creative Commons License

Advertisements

3 thoughts on “Windows 10 – Universal Windows Platform – Toast Input

    • I see – for those kind of Push Notifications it requires a service which isn’t easily usable by everyone but I’ll think about doing something on the RoguePlanetoid.com blog about this

      Like

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