Silverlight 4 includes a slew of features designed to make out-of-browser applications richer. One of those features is notification windows, also known as “toast” windows. This feature is available to all OOBs, regardless of whether they are trusted. It is not available to applications that run inside the browser.

A notification window is one that pops up in the lower right corner of the screen, similar to the ones that Outlook uses to notify users about incoming e-mails. (On the Macintosh, notification windows appear at the top of the screen rather than the bottom.) Notification windows are normally used to let the user know something important has happened. A classic use for them is to inform the user that an updated version of an out-of-browser application is available when the OOB is launched from the desktop or Start menu:

Notification window

This notification window was created by first declaring a user control named UpdateNotification that contained the following content:

<Grid x:Name=”LayoutRoot”>

    <Border x:Name=”Frame” Width=”300″ Height=”100″ Background=”LightYellow”>

        <StackPanel Orientation=”Vertical”>

            <Border Width=”290″ Height=”24″ CornerRadius=”4″ Margin=”2,4,2,4″>


                    <LinearGradientBrush StartPoint=”0.5,0.0″


                        <GradientStop Offset=”0.2″ Color=”#FF1C68A0″ />

                        <GradientStop Offset=”1.0″ Color=”#FF54A7E2″ />




                    <DropShadowEffect BlurRadius=”4″ ShadowDepth=”4″

                        Opacity=”0.4″ />


                <TextBlock Text=”Update Available” FontSize=”12″

                    FontWeight=”Bold” Foreground=”White” Margin=”4″ />


            <StackPanel Orientation=”Horizontal”>

                <Image Source=”Images/Update.png” Width=”32″ Height=”34″

                    Stretch=”Fill” Margin=”4″ VerticalAlignment=”Top” />

                <TextBlock Width=”240″ Text=”An updated version…”

                    FontSize=”11″ Foreground=”#FF202020″ TextWrapping=”Wrap”

                    Margin=”4″ />






Then it was displayed by creating an instance of System.Windows.NotificationWindow, instantiating the user control and assigning it to the NotificationWindow’s Content property, and calling NotificationWindow.Show:


NotificationWindow win = new NotificationWindow();

UpdateNotification un = new UpdateNotification();

win.Width = un.Width;

win.Height = un.Height;

win.Content = un;


The parameter passed to NotificationWindow.Show is a time-out parameter that specifies how long the notification window will be displayed—in this case, 10 seconds. If desired, you can call NotificationWindow.Close to close the notification window early—for example, in response to a mouse click.

Another new feature available only to OOBs is the ability to interact with host windows. In Silverlight 3, out-of-browser applications had limited control over their environment. It was not possible, for example, for an OOB to resize the window in which it was hosted.

This changes in Silverlight 4 with the addition of the System.Windows.Window class and the new Application.MainWindow property. An out-of-browser application can get a reference to its window through the MainWindow property, and it can use Window properties and methods to interrogate and even modify the host window. The following code snippet resizes the host window programmatically:

Window win = Application.Current.MainWindow;

win.Width = 1024;

win.Height = 768;

The Window class also features properties named Left and Top for repositioning host windows, WindowState for minimizing, maximizing, and restoring host windows, and TopMost for controlling the host window’s topmost state. And it includes an Activate method for bringing a host window to the foreground and assigning it the focus.