Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ChildWindow.Closed Event

Silverlight

Occurs when the ChildWindow is closed.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)

public event EventHandler Closed
<sdk:ChildWindow Closed="eventHandler"/>

To access the property values of a child window, handle the Closed event in the code-behind page of the calling window. In the Closed event handler cast the sender parameter to a ChildWindow or a derived class to access the child window properties.

The following example demonstrates how to handle the Closed event in the code-behind page of the parent window. The LoginWindow class is derived from ChildWindow. In the button click event handler, the LoginWindow is instantiated and a handler for the Closed event is attached. In the Closed event handler, the sender parameter is cast to a LoginWindow. It is then used to access the DialogResult property and the Name text box. This example is part of a larger example available in the ChildWindow class overview.


private void Button_Click(object sender, RoutedEventArgs e)
{
    LoginWindow loginWnd = new LoginWindow();
    loginWnd.Closed += new EventHandler(loginWnd_Closed);
    loginWnd.Show();
}
void loginWnd_Closed(object sender, EventArgs e)
{
    LoginWindow lw = (LoginWindow)sender;

    if (lw.DialogResult == true && lw.nameBox.Text != string.Empty)
    {
        this.helloTxt.Text = "Hello " + lw.nameBox.Text;
    }
    else if (lw.DialogResult == false)
    {
        this.helloTxt.Text = "Login canceled.";
    }
}


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft