This project has moved. For the latest updates, please go here.

ChildWindow as root element

Feb 22, 2013 at 3:13 PM
Edited Feb 22, 2013 at 3:14 PM
Hello.

I'm trying to use the ChildWindow control similarly to Silverlight. i.e I want a XAML file with the <ChildWindow> tag as the root element.
<xctk:ChildWindow x:Class="Azur.ProtoWPF.WPF.UI.Modules.App1.Dialogs.UserControl1"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                  xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
                  Width="500"
                  Height="500"
                  d:DesignHeight="300"
                  d:DesignWidth="300"
                  mc:Ignorable="d">
    <Grid>
        <TextBlock HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   FontFamily="Calibri"
                   FontSize="24"
                   FontWeight="Bold"
                   Foreground="Green"
                   Text="Hello Child Window" />
    </Grid>
</xctk:ChildWindow>
And then I call it from codebehind, by calling the constructor and the show() method:
     UserControl1 msg = new UserControl1();
            msg.IsModal = true;
            msg.Show();
However, nothing happens. I do not get any exceptions, but the window never shows. Am I doing this right? Can I use the ChildWindow that way? Thanks!
Apr 29, 2013 at 11:20 AM
Edited Apr 29, 2013 at 11:20 AM
This may be an old question, but if it helps anyone else you need to add the window to the UI tree before showing it.
Something like this:
            MyDialog dialog = new MyDialog();
            LayoutRoot.Children.Add(dialog);
            dialog.Closed += (s, ea) =>
                {
                    LayoutRoot.Children.Remove(dialog);
                };
            dialog.Show();