How to use the ChildWindow


How to create a ChildWindow

  1. Create a new UserControl and give it a name (let's call it "ChildWindow1"). To create a new UserControl, right-click on your project in the Solution Explorer, and click Add => New Item => C# XAML for HTML5 => User Control.
  2. Edit both the XAML and C# of the UserControl, and replace every instance of the word "UserControl" with "ChildWindow". For example, your XAML should begin with <ChildWindow... and end with </ChildWindow>, and your C# class should inherit from ChildWindow.
  3. To make the ChildWindow appear, use the following code:
    var childWindow1 = new ChildWindow1();

Notes and other features

  • If you want, you can give a title to your ChildWindow by setting it in XAML, like so: <ChildWindow Title="My Child Window" ...
  • It is recommended that you give a fixed size (in pixels) to your ChildWindow, otherwise it may not show properly. You can do so by setting the size in XAML, like this: <ChildWindow Width="300" Height="200"...
  • you want, you can register the "Closed" event to retrieve the dialog result. Here is how:
    childWindow1.Closed += new EventHandler(ChildWindow1_Closed);
    void ChildWindow1_Closed(object sender, EventArgs e)
        var childWindow1 = (ChildWindow1)sender;
        MessageBox.Show("The result is: " + childWindow1.DialogResult.ToString());
  • You can set the result from within the ChildWindow using the following code:
    this.DialogResult = true; // This will automatically close the ChildWindow.
    If you want to pass a value other than boolean, you can add a property to your ChildWindow implementation and set it to the desired value.
  • If you want, in your ChildWindow code, you can register the "Closing" event to check for data validity, and abort the closing operation by setting e.Cancel = true;


Contact Us

Please click here for contact information.