Silverlight Tip of the Day #74 - Monitoring for App.Current Events - Startup, UnhandledException & Exit.
Ever noticed there was an event off the Page class called Loaded() that tells you when the page is loaded but none for for Exit() or Quit()?
Example for Page.Loaded():
public Page()
{ InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
}
One way to monitor for the Exit() event in your Page class is to subscribe to the App.Current.Exit() event. Example:
public Page()
{ InitializeComponent();
App.Current.Exit += new EventHandler(Current_Exit);
}
void Current_Exit(object sender, EventArgs e)
{
}
In addition to the Exit() event there is also:
- App.Current.Startup()
- App.Current.UnhandledException()
Thank you,
--Mike Snow
Subscribe in a reader