Click here to Skip to main content
Licence CPOL
First Posted 20 Nov 2009
Views 7,720
Downloads 143
Bookmarked 13 times

Silverlight 4: Implementing Notification Using New APIs

By | 20 Nov 2009 | Article
This article demonstrates all the new notification features in Silverlight 4.

Introduction

The Silverlight Notification API is a new feature introduced in Silverlight 4 Beta 1. If you are developing your application using Silverlight, and want to show some notification messages like Outlook to the user, then you can use this. Remember that this feature only works out of browser.

Background

To develop Silverlight 4 applications, you must need Visual Studio 2010 Beta 2, which you can download from the Microsoft site. If you are using Visual Studio 2008, then you can install Visual Studio 2010 side by side too. After you have installed the studio, just go with the installation of the “Silverlight 4 Tools for Visual Studio 2010”.

Use of the Code

After you setup your development environment, create a new Silverlight 4 application using Visual Studio 2010. This will automatically create a page “MainPage.xaml” for you. Add two buttons in your XAML: one to install the Silverlight application as out of browser, and another to show the notification.

<Button x:Name="btnInstall" Width="150" 
    Height="20" Content="Install OOB" Margin="5"/>
<Button x:Name="btnShowNotification" Width="150" 
  Height="20" Content="Show Notification" Margin="5"/>

For implementing the Silverlight out of browser feature, follow my earlier post: “How can you implement the Silverlight 3 Out-Of-Browser feature?” Now go to the code-behind file “MainPage.xaml.cs” and implement the Click event for those. On page load, if it is running out of browser, then create the notification window instance:

// Initialize a new instance of Notification Window
notificationWindow = new NotificationWindow();
notificationWindow.Height = 50.0;
notificationWindow.Width = 300.0;

Create your custom notification panel either using XAML or code-behind. You can go for a nice looking UserControl. Here, for example, I will use a TextBlock inside a Border to show a simple message.

Border border = new Border()
{
    Background = new SolidColorBrush(Colors.Gray),
    Height = notificationWindow.Height,
    Width = notificationWindow.Width,
    Child = new TextBlock()
    {
        Text = "This is a Custom Notification from Silverlight 4",
        Foreground = new SolidColorBrush(Colors.White)
    }
};

Now, on the “Show Notification” button click event, check for whether it is running out of browser. If so, assign the notification panel you created to the content of the notification window instance and call the Show method of the notification window. Here, you have to pass the duration of the visibility of the notification in milliseconds.

notificationWindow.Content = border; // add the custom notification panel
notificationWindow.Show(2000); // show the notification

Now, run your application and click on the “Install OOB” button. This will install the Silverlight application and open the desktop version of it. Click the “Show Notification” button to show the notification at the right bottom corner of your desktop.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

_ Kunal Chowdhury _

Software Developer

India India

Member

Follow on Twitter Follow on Twitter
Kunal Chowdhury is a Microsoft MVP (Most Valuable Professional) in Silverlight Technology, a Codeproject MVP & Mentor, DZone MVB (Most Valuable Blogger), Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.
 
He is currently working as a Software Engineer II in an MNC located at Pune, India. He has a very good skill over XAML, C#, Silverlight and WPF. He has a good working experience in Windows 7 application (including Multi-touch) development too.
 
He posts his findings in his technical blog. He also writes for SilverlightShow and Codeproject portal. Many of his articles were highlighted as "Article of the Day" in Microsoft sites.
 
He also has another website called Silverlight-Zone.com where he posts article links on Silverlight, Windows Phone 7 and XNA accumulated from various web sites to help the community grow on specified technologies.
 
You can reach him in his Blog : http://www.kunal-chowdhury.com
He is also available in Twitter : http://twitter.com/kunal2383

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 21 Nov 2009
Article Copyright 2009 by _ Kunal Chowdhury _
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid