|
App.xaml
<Application x:Class="WpfApplication_LifeCyclew.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup"
Activated="Application_Activated"
Deactivated="Application_Deactivated"
Exit="Application_Exit"
DispatcherUnhandledException="Application_DispatcherUnhandledException"
SessionEnding="Application_SessionEnding"
>
<Application.Resources>
</Application.Resources>
</Application>
App.xaml.cs
public partial class App : Application
{
bool isApplicationActive;
/// <summary>
/// StartupUri="Window1.xaml"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Application_Startup(object sender, StartupEventArgs e)
{
Window2 win = new Window2();
win.Show();
}
private void Application_Activated(object sender, EventArgs e)
{
this.isApplicationActive = true;
}
private void Application_Deactivated(object sender, EventArgs e)
{
this.isApplicationActive = false;
}
private void Application_Exit(object sender, ExitEventArgs e)
{
Application.Current.Shutdown(-1);
}
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message);
}
private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
string msg = string.Format("{0}. End session?", e.ReasonSessionEnding);
e.Cancel = true;
}
private void Application_Exit(object sender, ExitEventArgs e)
{
Application.Current.Shutdown(-1);
}
}
|