Windows 8 demo-Toast notifications

I have had requests to share the Windows 8 demos that I gave at the Windows 8 Developer camp. The source code for this blog post is available on Github at https://github.com/DavidBurela/Win8Demo-Notifications

Toast notifications allow your application to prompt your users when something has happened in your application that may not be currently viewable on the screen. An example being an auction application. The user flags to watch an item. The user than navigates away and looks at other items. Later the application can show a toast notification warning the user that there is only 5 minutes of bidding remaining.

IMPORTANT

Ensure that go into your application manifest and set Toast Enabled to Yes. If you are submitting a ToastNofication to the ToastNotificationManager and see no error messages, but toasts are failing to show. Then you have probably not enabled toasts in your application.

Simple text toast notification

Notification toasts in your application can be created by sending a formatted XML message to the ToastNotificationManager. The easiest way to achieve this is to get a base template for the notification style that you want (Text only, Image, Image and Text, etc) then modifying the Text or Image elements of the XML template. The code below shows how a XML template can be taken and updated with custom text. The XML document is then used to create a ToastNotification which is then sent to the ToastNotificationManager.

/// <summary>
/// Raises a text toast notification locally.
/// IMPORTANT: if copying this into your own application, ensure that “Toast capable” is enabled in the application manifest
/// </summary>private void NotificationTextButton_Click(object sender, RoutedEventArgs e)
{
// Toasts use a predefined set of standard templates to display their content.
// The updates happen by sending a XML fragment to the Toast Notification Manager.
// To make things easier, we will get the template for a toast iwth text as a base, and modify it from there
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);

// Find the ‘text’ element in the template’s XML, and insert the text “A sample toast” into it.
var elements = toastXml.GetElementsByTagName(“text”);
elements[0].AppendChild(toastXml.CreateTextNode(“A sample toast”));

// Create a ToastNotification from our XML, and send it to the Toast Notification Manager
var toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}

image

Toast notification with a local image and text

Images can be shown in the toast notification easily by create a Image element in the XML document. The templates can be used again as a base to start with, but this example will construct the XML document from scratch by creating a ToastImageAndTest01 toast. The image and text elements are created, finally the XML document is chained together. The XML is used to create a ToastNotification which is passed to the ToastNotificationManager

private void NotificationImageButton_Click(object sender, RoutedEventArgs e)
{
// It is possible to start from an existing template and modify what is needed.
// Alternatively you can construct the XML from scratch.
var toastXml = new XmlDocument();
var title = toastXml.CreateElement(“toast”);
var visual = toastXml.CreateElement(“visual”);
visual.SetAttribute(“version”, “1″);
visual.SetAttribute(“lang”, “en-US”);

// The template is set to be a ToastImageAndText01. This tells the toast notification manager what to expect next.
var binding = toastXml.CreateElement(“binding”);
binding.SetAttribute(“template”, “ToastImageAndText01″);

// An image element is then created under the ToastImageAndText01 XML node. The path to the image is specified
var image = toastXml.CreateElement(“image”);
image.SetAttribute(“id”, “1″);
image.SetAttribute(“src”, @”Assets/DemoImage.png”);

// A text element is created under the ToastImageAndText01 XML node.
var text = toastXml.CreateElement(“text”);
text.SetAttribute(“id”, “1″);
text.InnerText = “Another sample toast. This time with an image”;

// All the XML elements are chained up together.
title.AppendChild(visual);
visual.AppendChild(binding);
binding.AppendChild(image);
binding.AppendChild(text);

toastXml.AppendChild(title);

// Create a ToastNotification from our XML, and send it to the Toast Notification Manager
var toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}

image

More toasts

Images from remote web servers can be used. This can be done easily by specifying a remote URI instead of the local path within the application.

To get the XML required for other templates, download the official SDK sample, run the application, click the type of notification you would like, and take note of the outputted XML on the screen http://code.msdn.microsoft.com/windowsapps/Toast-notifications-sample-52eeba29

Community report – XDDN Melbourne April

Ian Randal (@kiwipom) spoke at the XDDN Melbourne April meeting.

He lightly touched on what IoC is, in the context of how Caliburn.Micro uses it. He then went on to show some demos of  Caliburn.Micro. He demonstrated how a XAML page can be created which binds to a ViewModel, without requiring any “UI glue code” to stick it all together. It made for a simple application that had a higher percentage of the code being business logic, rather than scaffolding.

A recording of the talk can be found below


https://vimeo.com/41073059/

Windows 8 demo–Updating application tiles

I have had requests to share the Windows 8 demos that I gave at the Windows 8 Developer camp. The source code is available on Github at https://github.com/DavidBurela/Win8Demo-Tiles

Text tile

Application tiles in your application can be updated by sending a formatted XML message to the TileUpdateManager. The easiest way to achieve this is to get a base template for the tile style that you want (Text only, Image, Image and Text, etc) then modifying the Text or Image elements of the template. The code below shows how a XML template can be taken and updated with custom text. The XML document is then used to create a TileNoficitacion which is then sent to the TileUpdateManager.

/// <summary>
/// Set the application's tile to display text content.
/// After clicking, go back to the start screen to watch your application's tile update.
/// </summary>
private void SetTileTextButtonClick(object sender, RoutedEventArgs e)
{
    // Tiles use a predefined set of standard templates to display their content.
    // The updates happen by sending a XML fragment to the Tile update manager.
    // To make things easier, we will get the template for a square tile with text as a base, and modify it from there
    var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText01);

    // Find the 'text' element in the template's XML, and insert the text "Hi :-) " into it.
    var elements = tileXml.GetElementsByTagName("text");
    elements[0].AppendChild(tileXml.CreateTextNode("Hi :-) "));

    // Create a TileNotification from our XML, and send it to the Tile update manager
    var tileNotification = new TileNotification(tileXml);
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
}

 

Image tile from local image file

It is also possible to create the XML from scratch and send it to the TileUpdateManager. The code below updates the application tile with an image tile. It starts by instantiating a XmlDocument, creating each of the XML elements, and then chaining the elements together to form the final XML document.

The path to the image is given as being a local application resource through the convention ms-appx:///Assets/DemoImage.png

/// <summary>
/// Set the application's tile to display a local image file.
/// After clicking, go back to the start screen to watch your application's tile update.
/// </summary>
private void SetTileImageButtonClick(object sender, RoutedEventArgs e)
{
    // It is possible to start from an existing template and modify what is needed.
    // Alternatively you can construct the XML from scratch.
    var tileXml = new XmlDocument();
    var title = tileXml.CreateElement("title");
    var visual = tileXml.CreateElement("visual");
    visual.SetAttribute("version", "1");
    visual.SetAttribute("lang", "en-US");

    // The template is set to be a TileSquareImage. This tells the tile update manager what to expect next.
    var binding = tileXml.CreateElement("binding");
    binding.SetAttribute("template", "TileSquareImage");
    // An image element is then created under the TileSquareImage XML node. The path to the image is specified
    var image = tileXml.CreateElement("image");
    image.SetAttribute("id", "1");
    image.SetAttribute("src", @"ms-appx:///Assets/DemoImage.png");

    // All the XML elements are chained up together.
    title.AppendChild(visual);
    visual.AppendChild(binding);
    binding.AppendChild(image);
    tileXml.AppendChild(title);

    // The XML is used to create a new TileNotification which is then sent to the TileUpdateManager
    var tileNotification = new TileNotification(tileXml);
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
}

 

Image tile from remote image

A remote image can be used by again using a template (or hand crafting the XML from scratch as in the previous example), but this time providing a URI to an image hosted on a remote web server, rather than a local application resource.

/// <summary>
/// Set the application's tile to display a remote image on the internet.
/// After clicking, go back to the start screen to watch your application's tile update.
/// </summary>
private void SetTileRemoteImageButtonClick(object sender, RoutedEventArgs e)
{
    var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareImage);

    // Find the 'image' element in the template's XML. Change the src attribute to a remote URL
    var elements = tileXml.GetElementsByTagName("image");
    var imageElement = elements[0] as XmlElement;
    imageElement.SetAttribute("src", @"http://i.microsoft.com/global/en-us/homepage/PublishingImages/sprites/microsoft.png");

    // Create a TileNotification from our XML, and send it to the Tile update manager
    var tileNotification = new TileNotification(tileXml);
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
}

Again, this source code is available as a working example on Github at https://github.com/DavidBurela/Win8Demo-Tiles

Windows 8 developer camp companion application + source code

I put aside a few hours over the weekend and created a companion application for the “Windows 8 developer camps” that are currently running all around Australia. http://www.lalaninja.com.au/2012/03/19/windows-8-developer-camps-australia/

It only took a few hours to throw something simple together for the attendees. The application provides some basic features to help out on the day

  • Daily schedule
  • Dates
  • XDDN details. So that attendees can continue with their Windows 8 learning
  • Links to online Windows 8 developer resources
  • Links to source code of the demos I gave in my presentations (submitted in pending app update)

Download the Windows Phone 7 marketplace right now
http://www.windowsphone.com/en-AU/apps/1a7853b1-1d2c-4d1c-9ba1-6d709053eced

I have made the source code available for anyone that wants to see how a simple app can be put together in only a few hours and submitted to the marketplace.
https://github.com/DavidBurela/Windows8DeveloperCampPhoneApplication

scheduleXDDN informationonline resources

XDDN around Australia

To try and streamline the XDDN groups around Australia, I have been working with the organisers of the other cities to create a few central locations for everything.
For those unfamiliar with XDDN, it is a usergroup I run that focuses on UX, Design and Development on Microsoft UI platforms. Such as Win8, WinPhone7, HTML5, etc.

The main reason for moving everything to Meetup is that it allows everyone to easily see upcoming events and get automatically notified when new events are created.
Having XDDN on Meetup.com also supports my other goals of getting more people involved with their local development communities. Joining the groups will allow you to easily find other local groups that you may want to attend, such as Agile or Alt.Net groups.
Please join the group for your city, as the old event sites (such as EventBrite) will be slowly decommissioned over the next few weeks.

XDDN Melbourne – April meeting

This month I have organised for Ian Randall (@Kiwipom) to talk at the April XDDN meeting.

I have also created a new twitter account @XDDN_AU from which I will be tweeting all of the sessions for Melbourne, Sydney & Perth. Be sure to follow it.

Register here: http://xddn-melbourne-april2012.eventbrite.com/

Learn about creating great MVVM applications with LESS CODE. Ian Randall will be demonstrating how to use Caliburn.Micro to create cleaner XAML based applications. These techniques will work with WinRT (Windows 8), Silverlight, Windows Phone 7 and WPF.
Caliburn.Micro can be downloaded at http://caliburnmicro.codeplex.com/

Time: 5:30 pm networking & pizza.
6:00 pm presentations start.

Caliburn.Micro – Ian Randall

Caliburn.Micro (http://caliburnmicro.codeplex.com/) is more than just an MVVM library, it’s a client application framework that works every bit as hard for your app that a web framework does: Logging, composition, binding, and much, much more.
This session will cover getting started with Caliburn.Micro and give practical demonstrations of Convention Over Configuration, Actions, Screens & Conductors and will go a bit deeper under the covers (if we get time).

Ian Randall is a software developer for Datacom in Auckland and a XAML geek on the internets. He helps to run the Metro Meetup in Auckland and just spent the last 6 months putting on ‘codemania’ (http://codemania.co.nz). He is currently trying to catch a breath…
He loves Melbourne, partly for the friendly Victorian people, but mostly for @aeoth’s legendary chocolate brownies.

I’m presenting at the Melbourne Windows 8 developer camp

With the approach of Windows 8, Microsoft is organising a number of 1 day developer camps in capital cities all around Australia.
I am helping out with the Melbourne camp this weekend, there are still a few places left if you want to attend.

Date: Saturday 31st March
Location: Microsoft office, Melbourne
Registration: https://msevents.microsoft.com/cui/EventDetail.aspx?culture=en-AU&EventID=1032507239&IO=ImoI4B2Taytfc9qzXGdYAQ%3d%3d

 

A full list of camps around Australia can be found at http://www.lalaninja.com.au/2012/03/19/windows-8-developer-camps-australia/

I’m speaking at the Melbourne March XDDN

I’m speaking at Melbourne XDDN this month. With the Windows 8 Consumer Preview released, now is the perfect time to reexamine Windows 8. Below are the meeting details:

Register here: http://xddn-melbourne-march2012.eventbrite.com/
Date: Wed 21st March
Time: 5:30 networking & pizza. 6pm presentations start

A tour around Windows 8 – David Burela
Windows 8 has been announced to the public and is being branded as “Windows reimagined”. This introductory session will show some of the new features coming with Windows 8.
A touch first interface, user account syncing via the cloud, “charms”, app to app data sharing, and the ability to use a picture password to log into windows will all be demonstrated.

Getting started with Windows 8 development – David Burela
So you’ve heard that Windows 8 has a new way of applications known as “Metro styled immersive apps”, but what does this actually mean? What is WinRT? Is Microsoft really making developers use HTML5 to create desktop apps? What about your previous investments in Silverlight?
Join David Burela as he helps clarify what the new programming model is and what impact it will have on you. Explanations of WinRT and how to create basic applications will be shown.

Melbourne January NerdDinner

As it is too early in the year for most usergroups to start again for 2012, I thought it would be a great chance to organise a Nerd Dinner to kick the year off with.

Location: The Elephant & Wheelbarrow
94-96 Bourke Street, Melbourne
When: Jan 25th 6:30pm

http://www.nerddinner.com/5288

I’m speaking at the Melbourne September XDDN

I’m speaking at the Melbourne XDDN this month. Now that Windows 8 and the WinRT programming model has been released, it makes sense to focus on them. Below are the meeting details:

Register here: http://sddn-sep-2011.eventbrite.com/
Date: Tue 27 Sep
Time: 5:30 networking & pizza. 6pm presentations start

A tour around Windows 8 – David Burela
Windows 8 has been announced to the public and is being branded as “Windows reimagined”. This introductory session will show some of the new features coming with Windows 8.
A touch first interface, user account syncing via the cloud, “charms”, app to app data sharing, and the ability to use a picture password to log into windows will all be demonstrated.

Getting started with Windows 8 development – David Burela
So you’ve heard that Windows 8 has a new way of applications known as “Metro styled immersive apps”, but what does this actually mean? What is WinRT? Is Microsoft really making developers use HTML5 to create desktop apps? What about your previous investments in Silverlight?
Join David Burela as he helps clarify what the new programming model is and what impact it will have on you. Explanations of WinRT and how to create basic applications will be shown.

Follow

Get every new post delivered to your Inbox.