Window Object In WPF

The Window object provides properties, methods, and events that allow the application to respond and it is used to handle interaction with the user. Each WPF application has a reference to a window , which is designated by the main window .We can control this setting by the MainWindow property of the Application object. In order to access the Window object, we should first give the reference of the MainWindow Object.

 

NavigationWindow nw = (NavigationWindow)MyApplication.MainWindow;

 

Here we take a simple example of window object. Here we use an event of the Window object ContentRendered, By this the Window Content Has been Rendered.

 

First we write  the following  in Window.xaml:

 

<Window x:Class="Window_Object_In_WPF.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Window1" Height="300" Width="300" ContentRendered="OnContentRendered">

 

Then we write the following event handler in the code behind file:

 

private void OnContentRendered(object sender, EventArgs e)

        {

            MessageBox.Show("My Name is Mahak");

        }


The following Window will be appear, when we run the program:


 Window.png