NotificationWindow in Silverlight (Out of Browser Apps)
Silverlight 4 brings another feature to desk - NotificationWindow. NotificationWindow is different from PopUp in following ways:
- NotificationWindow opens as a Splash Screen, while PopUp does not.
- NotificationWindow has an expiry time (set in MilliSeconds); while PopUp needs to be closed explicitly
- NotfificationWindow can be implemented only for Out-Of-Browser applications; PopUp can be used for both Web and Out-Of-Browser applications
With that, let's see how to implement NotificationWindow for Silverlight Applications.
Statement - Create NotificationWindow to denote a Upgrade Window
First, we will design a NotificationWindow - Create a New Silverlight UserControl and give it name: UpgradeWindow
[sourcecode language='xml']
[/sourcecode]
Next, we define a Model class for UpgradeWindow - UpgradeWindowModel.cs
[sourcecode language='csharp']
public class UpgradeWindowModel : INotifyPropertyChanged
{
private string _title;
public string Title
{
get
{
return _title;
}
set
{
_title = value;
OnPropertyChanged(value);
}
}
private string _content;
public string Content
{
get
{
return _content;
}
set
{
_content = value;
OnPropertyChanged(value);
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
[/sourcecode]
Further, we invoke this UpgradeWindow in our MainPage.cs
[sourcecode language='csharp']
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
LoadPopUpWindowInOutofBrowser();
}
private void LoadPopUpWindowInOutofBrowser()
{
NotificationWindow win = new NotificationWindow();
UpgradeWindow un = new UpgradeWindow();
un.DataContext = new UpgradeWindowModel { Title = "Checking for upgrades",
Content ="Downloading content..." };
win.Width = un.Width;
win.Height = un.Height;
win.Content = un;
win.Show(10000);
}
}
[/sourcecode]
And, the NotificationWindow will be displayed when the application is executed.