Toast Notifications are a new feature that is supported in Out-of-Browser Silverlight applications. Toast windows are essentially temporary notification windows that appears in the bottom right of your screen. They are useful for providing users with information about something that might need their immediate attention. Applications like Instant Messaging and Outlook are good examples of applications that leverage this type of window.
Restrictions (for security reasons):
1. The maximum size is fixed (max 400×100 in dimension).
2. You can not use effects such as transparency.
3. Normal window border/chrome is not available so that the window is easily identifiable as a notification window.
Step #1: To create a Notification Window start by making your application run in Out of Browser mode. See my blogs on creating OOB applications (http://www.silverlightdev.net/?p=86) and Configure your app to run in OOB mode from VS (http://www.silverlightdev.net/?p=89).
Step #2: In your XAML, add a button that will open the Notification window when clicked:
<Button x:Name="MyButton" Content="Show Window" Click="MyButton_Click"
Width="130" Height="40" FontSize="13"/>
Step #3: Create your NotificationWindow object:
NotificationWindow _window = null;
public MainPage()
{
InitializeComponent();
if (true == App.Current.IsRunningOutOfBrowser)
{
_window = new NotificationWindow();
TextBlock notificationMsg = new TextBlock();
notificationMsg.Text = "Hello World";
_window.Content = notificationMsg;
}
}
Step #4: Showing the Window.
Finally, in your button click event verify the window is not already opened. Note that only one notification window can be shown at a time. Call NotificationWindow.Sow() to open the window specifying the duration you want the window to be opened in milliseconds.
private void MyButton_Click(object sender, RoutedEventArgs e)
{
if (null == _window)
MessageBox.Show("Notification windows require you to be running in OOB mode. \n\nTo proceed, right click on this app and choose to install this app on this computer.\n\nThank you.");
if (true == App.Current.IsRunningOutOfBrowser)
{
if (_window.Visibility == Visibility.Visible)
_window.Close();
_window.Show(2000);
}
}
Source: Tip6_ToastNotifications
Demo:
[silverlight: Tip6_ToastNotifications.xap]
Thanks,
–Mike






