WPF sample
(Nothing new, codes taken from MSLearning)
<Application x:Class="MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
Startup="MyApp_Startup"
Activated="MyApp_Activated"
Deactivated="MyApp_Deactivated"
SessionEnding="MyApp_SessionEnding"
Exit="MyApp_Exit"
</Application>
C#
public class MyApp : Application
{
StackPanel rootPanel;
Window win;
protected override void OnStartup(StartupEventArgs e)
{
win = new System.Windows.Window();
rootPanel = new StackPanel();
win.Content = rootPanel;
win.Show();
}
void MyApp_Startup (object sender, StartupEventArgs e)
{
//singleton model and where sharing information pages uses Properties.
MyApp.Current.Properties["TextFromPage1"] = txtBox.Text;
// Retrieve the information
string appPropertyValue;
appPropertyValue = (string)MyApp.Current.Properties["TextFromPage1"];
}
void MyApp_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
//trigger if user shut down system or log off and application hasn't exit.
//session ending then application exit
}
void MyApp_Activated(object sender, EventArgs e)
{
}
}
internal sealed class TestMain
{
[System.STAThread()]
public static void Main()
{
MyApp app = new MyApp();
app.Run();
}
}
<Application x:Class="MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
Startup="MyApp_Startup"
Activated="MyApp_Activated"
Deactivated="MyApp_Deactivated"
SessionEnding="MyApp_SessionEnding"
Exit="MyApp_Exit"
</Application>
C#
public class MyApp : Application
{
StackPanel rootPanel;
Window win;
protected override void OnStartup(StartupEventArgs e)
{
win = new System.Windows.Window();
rootPanel = new StackPanel();
win.Content = rootPanel;
win.Show();
}
void MyApp_Startup (object sender, StartupEventArgs e)
{
//singleton model and where sharing information pages uses Properties.
MyApp.Current.Properties["TextFromPage1"] = txtBox.Text;
// Retrieve the information
string appPropertyValue;
appPropertyValue = (string)MyApp.Current.Properties["TextFromPage1"];
}
void MyApp_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
//trigger if user shut down system or log off and application hasn't exit.
//session ending then application exit
}
void MyApp_Activated(object sender, EventArgs e)
{
}
}
internal sealed class TestMain
{
[System.STAThread()]
public static void Main()
{
MyApp app = new MyApp();
app.Run();
}
}
Comments