ChildWindow.Closing Event

Occurs when the ChildWindow is closing.

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

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.

NoteNote:

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"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           Width="300" Height="200" 
           Title="Login Window"
           Closing="ChildWindow_Closing">



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.";
        cw.Show();
    }
}


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

Show: