ChildWindow.Closing Event

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

Occurs when the ChildWindow is closing.

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


Public Event Closing As EventHandler(Of CancelEventArgs)
public event EventHandler<CancelEventArgs> Closing
<sdk:ChildWindow Closing="eventHandler"/>


This event occurs immediately after Close is called, and can be handled to cancel the closing of the child window. To cancel the closing of the child window, set the Cancel property to true.


Closing of the child window cannot be canceled if the application is exiting.


The following example demonstrates how to handle the Closing event and cancel the closure of the child window. The code checks the content of the Name and Password text boxes when the user clicks OK. If either text box is empty, the closing of the login window is canceled, and another ChildWindow is opened to display instructions to the user. This example is part of a larger example available in the ChildWindow class overview.

Run this sample

<!-- NOTE: 
  By convention, the sdk prefix indicates a URI-based XAML namespace declaration 
  for Silverlight SDK client libraries. This namespace declaration is valid for 
  Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace 
  declarations for each CLR assembly and namespace combination outside the scope 
  of the default Silverlight XAML namespace. For more information, see the help 
  topic "Prefixes and Mappings for Silverlight Libraries". 
<sdk:ChildWindow x:Class="ChildWindowLogin.LoginWindow"
           Width="300" Height="200" 
           Title="Login Window"
Private Sub ChildWindow_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
    If Me.DialogResult = True AndAlso _
            (Me.nameBox.Text = String.Empty OrElse Me.passwordBox.Password = String.Empty) Then
        e.Cancel = True
        Dim cw As New ChildWindow
        cw.Content = "Please enter name and password or click Cancel."
    End If
End Sub
private void ChildWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    if (this.DialogResult == true && 
            (this.nameBox.Text == string.Empty || this.passwordBox.Password == string.Empty))
        e.Cancel = true;
        ChildWindow cw = new ChildWindow();
        cw.Content = "Please enter name and password or click Cancel.";

Version Information


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.