Application Object In WPF
The Application object
provides an interface between our application and system. It is accessible from
all WPF projects. It is the entry point of the WPF application, where the
initialization can take place. It works like global.asax file which manages
session and application information. Each virtual method corresponds to an event
by the same name. For example, the OnActivated virtual method raises the
Activated event within the Application object. So we can either override the
OnActivated method or create an event handler for the Activated event to insert
functionality at that point shortly after.
The Application object wraps a set of XAML files
and creates a shared data environment between the
Pages. The use of the Application object to share
variables across pages .
In this Example, we can access these properties at
any point within our application only by adding the data using a string key
value of Student .
Step 1: First we write the Following code:
public class Student
Student s=new Student();
Step2: After that we take a
we write the following code in the Onclick event
of the button. Now when we click on the button the MessageBox will be appear.
Here we see the FName as a message and LName as a caption.
private void button1_Click(object
sender, RoutedEventArgs e)
Student y = (Student)Application.Current.Properties["Student"];