Share via


ChildWindow.Closed Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when the ChildWindow is closed.

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

Syntax

'Declaration
Public Event Closed As EventHandler
public event EventHandler Closed
<sdk:ChildWindow Closed="eventHandler"/>

Remarks

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.

Examples

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 Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim loginWnd As New LoginWindow()
    AddHandler loginWnd.Closed, AddressOf loginWnd_Closed
    loginWnd.Show()
End Sub
Private Sub loginWnd_Closed(ByVal sender As System.Object, ByVal e As EventArgs)
    Dim lw As LoginWindow = CType(sender, LoginWindow)

    If lw.DialogResult = True AndAlso lw.nameBox.Text <> String.Empty Then
        Me.helloTxt.Text = "Hello " + lw.nameBox.Text
    ElseIf (lw.DialogResult = False) Then
        Me.helloTxt.Text = "Login canceled."
    End If
End Sub
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.";
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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