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

ChildWindow changes

Jul 3, 2013 at 9:12 AM
Hi All,

I have noticed after upgrading to 2.0 via nuget that the ChildWindow's behaviour has changed, after looking at the documentation for the ChildWindow again i found that it should be moved to a WindowContainer, bit now my window isn't showing up at all. No code has changed and i Update the WindowState of the ChildWindow via binding - find attached code:
 <ExtendedToolkit:WindowContainer Name="xWindowContainer">
            <ExtendedToolkit:ChildWindow Name="ChildWindow" WindowState="{Binding ChildWindowVisible, Mode=TwoWay}" Caption="{Binding ChildWindowCaption}" 
                                     WindowStartupLocation="Center" IsModal="True" CloseButtonVisibility="{Binding ChildWindowCanExit, Converter={StaticResource BooleanToVisibilityConverter}}" Loaded="ChildWindow_Loaded" 
                                     SizeChanged="ChildWindow_SizeChanged" Closing="ChildWindow_Closing">
                <ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding ChildContent}"/>
            </ExtendedToolkit:ChildWindow>

            <ExtendedToolkit:ChildWindow Name="ChildWindowError" WindowState="{Binding ErrorWindowVisible}" Caption="{Binding ErrorWindowCaption}" 
                                     WindowStartupLocation="Manual" IsModal="True" CloseButtonVisibility="{Binding ErrorWindowCanExit}" SizeChanged="ChildWindowError_SizeChanged" 
                                     Loaded="ChildWindowError_Loaded" Closing="ChildWindowError_Closing">
                <ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding ErrorContent}"/>
            </ExtendedToolkit:ChildWindow>
            
        </ExtendedToolkit:WindowContainer>
Am I missing something here?

Thanx
Developer
Jul 4, 2013 at 12:37 PM
Creating a new project with only a WindowContainer and 2 ChildWindows (without bindings) works fine. Here's the sample :

<xctk:WindowContainer Name="xWindowContainer">
        <xctk:ChildWindow Name="ChildWindow" WindowState="Open"  Caption="ChildWindow1" 
                                 WindowStartupLocation="Center" IsModal="True" CloseButtonVisibility="Visible">
            <ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="My Window Content"/>
        </xctk:ChildWindow>

        <xctk:ChildWindow Name="ChildWindowError" WindowState="Open" Caption="ErrorWindow" 
                                 WindowStartupLocation="Manual" IsModal="True" CloseButtonVisibility="Visible">
            <ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="Error Content"/>
        </xctk:ChildWindow>
</xctk:WindowContainer>
Jul 5, 2013 at 6:50 AM
Hi,

Thanx for the reply. I used your exact code and there are a few problems:

Although the window shows, it is not centered, not modal & the style seems to have changed since the previous update.

Any ideas?
Developer
Jul 5, 2013 at 12:10 PM
Hi,

Using only the code from BoucherS shows 2 ChildWindows (1 being centered and the other being TopLeft, as expected).
The 2 ChildWindows are modal (1 after the other, as expected).
No particular styles are applied (no style defined, as expected).

Can you be more precise on those points ?
Thanks.
Jul 8, 2013 at 7:13 AM
Edited Jul 8, 2013 at 8:15 AM
Hi,

I just noticed that the window are showing - but they are not showing above all of the other views on the same window, even though IsModal is set to True.

The problem now is that it does not seem that the controls have a Topmost property, is there another equivalent I should be using?

As for the style change I mentioned:

Old Style
New Style

I did not apply any styling to the window before, and now its style has changed since update.

Thank you
Developer
Jul 8, 2013 at 12:51 PM
Hi,

Try putting the Windowcontainer (which contains the childWindows) as the Topmost object.
<Grid>
  <Grid>
     <Grid.RowDefinitions>
         <RowDefinition />
         <RowDefinition />
         <RowDefinition />
     </Grid.RowDefinitions>
    <TextBlock Text="Test" />
    <TextBlock Grid.Row="1" Text="Test2" />
    <TextBlock Grid.Row="2" Text="Test3" />
  </Grid>

  <xctk:WindowContainer>
    <xctk:ChildWindow IsModal="True" WindowState="Open" />
    <xctk:ChildWindow IsModal="True" WindowState="Open" />
  </xctk:WindowContainer>
</Grid>
For the style, the childWindow should be using the Windows7 or Windows8 theme depending on your operating system. Is it the case ?
Jul 8, 2013 at 12:58 PM
Hi,

I did try putting the window container as topmost, but then controls behind the windowcontainer no longer work! Because you are clicking on the container and not the controls underneath it! As for the style, nothing has changed on my side, it is still the same machine etc.
Developer
Jul 9, 2013 at 11:51 AM
Edited Jul 9, 2013 at 11:52 AM
When the ChildWindow is modal, nothing but the ChildWindow should be available (the windowContainer blocks the controls behind). When this modal window is closed, and there are no more modal Windows open, the controls behind the windowcontainer should be available. Please have a look at the sample Windowcontainer from the ClickOnce app available at https://wpftoolkit.codeplex.com/.
Jul 10, 2013 at 7:03 AM
Edited Jul 11, 2013 at 8:36 AM
Maybe it will help if I post all of my code:
    <Grid x:Name="MainGrid">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="35"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" HorizontalAlignment="Stretch">
                <Border BorderBrush="Gray" BorderThickness="0,0,0,0.1">
                    <ContentControl Background="#FFF5F5F5">
                        <ToolBar Height="35" Background="Transparent" IsTabStop="False" ToolBarTray.IsLocked="True" Name="DionysusToolbar" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                 Loaded="DionysusToolbar_Loaded">
                            <ToolBar.Items>

                            </ToolBar.Items>
                        </ToolBar>

                    </ContentControl>
                </Border>
            </Grid>
            <Grid Grid.Row="1">
                <DockPanel LastChildFill="True">
                    <odc:OutlookBar IsTabStop="False" NavigationPaneText="Expand navigationbar to view" DockPanel.Dock="Left" x:Name="OutlookBar" Width="300" 
                                    AllowDrop="False" HorizontalContentAlignment="Left" IsButtonSplitterVisible="False" IsCloseButtonVisible="False" 
                                    IsManipulationEnabled="False" IsMaximized="True" IsOverflowVisible="False" ShowButtons="True" ShowSideButtons="True" Loaded="OutlookBar_Loaded" VerticalContentAlignment="Stretch" />
                    <ContentControl Content="{Binding MainContent}" Grid.Column="1"  Margin="0,0,2,0" Grid.Row="1"></ContentControl>
                </DockPanel>
            </Grid>
            <Border Grid.Row="2" BorderThickness="0,0.1,0,0" BorderBrush="Gray">
                <Grid Grid.Row="2">
                </Grid>
            </Border>
            <ContentControl Grid.RowSpan="3" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            HorizontalContentAlignment="Stretch" 
            VerticalContentAlignment="Stretch">
            </ContentControl>

        </Grid>

        <ExtendedToolkit:WindowContainer Name="xWindowContainer">
            <ExtendedToolkit:ChildWindow Name="ChildWindow" WindowState="{Binding ChildWindowVisible, Mode=TwoWay}" Caption="{Binding ChildWindowCaption}" 
                                     WindowStartupLocation="Center" IsModal="True" CloseButtonVisibility="{Binding ChildWindowCanExit, Converter={StaticResource BooleanToVisibilityConverter}}" Loaded="ChildWindow_Loaded" 
                                     SizeChanged="ChildWindow_SizeChanged" Closing="ChildWindow_Closing">
                <ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding ChildContent}"/>
            </ExtendedToolkit:ChildWindow>

            <ExtendedToolkit:ChildWindow Name="ChildWindowError" WindowState="{Binding ErrorWindowVisible, Mode=TwoWay}" Caption="{Binding ErrorWindowCaption}" 
                                     WindowStartupLocation="Center" IsModal="True" CloseButtonVisibility="{Binding ErrorWindowCanExit}" SizeChanged="ChildWindowError_SizeChanged" 
                                     Loaded="ChildWindowError_Loaded" Closing="ChildWindowError_Closing">
                <ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding ErrorContent}"/>
            </ExtendedToolkit:ChildWindow>

        </ExtendedToolkit:WindowContainer>

    </Grid>
This way the window is shown behind my "MainContent" content control. If i do put the WindowContainer after the grid or topmost, I cannot access any of the other control.

As I mentioned this all was working perfectly until I updated to 2.0.
Developer
Jul 10, 2013 at 1:10 PM
Hi,
I you want to have the ChilWindow in front of the other controls AND want to be able to edit the other controls, put the ChildWindow.IsModal to False. This way, the ChildWindow won't block the other controls...IsModal = true will block the other controls.

I try your code, with some small changes to simplify it, and putting the WindowContainer after the grid, make it worked as expected ;
The modalWindow blocks the other controls, until it is closed.

Here's the code I tried :
<Grid x:Name="MainGrid">

      <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="35"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" HorizontalAlignment="Stretch">
                <Border BorderBrush="Gray" BorderThickness="0,0,0,0.1">
                    <ContentControl Background="#FFF5F5F5">
                        <ToolBar Height="35" 
                                 Background="Transparent" 
                                 IsTabStop="False" 
                                 ToolBarTray.IsLocked="True" 
                                 Name="DionysusToolbar" 
                                 HorizontalAlignment="Stretch" 
                                 VerticalAlignment="Stretch">
                            <ToolBar.Items>

                            </ToolBar.Items>
                        </ToolBar>

                    </ContentControl>
                </Border>
            </Grid>
            <Grid Grid.Row="1">
                <DockPanel LastChildFill="True">
                    <!--<odc:OutlookBar IsTabStop="False" NavigationPaneText="Expand navigationbar to view" DockPanel.Dock="Left" x:Name="OutlookBar" Width="300" 
                                    AllowDrop="False" HorizontalContentAlignment="Left" IsButtonSplitterVisible="False" IsCloseButtonVisible="False" 
                                    IsManipulationEnabled="False" IsMaximized="True" IsOverflowVisible="False" ShowButtons="True" ShowSideButtons="True" Loaded="OutlookBar_Loaded" VerticalContentAlignment="Stretch" />-->
                     <xctk:Calculator DockPanel.Dock="Left"/>
                     <!--<ContentControl Content="{Binding MainContent}" Grid.Column="1"  Margin="0,0,2,0" Grid.Row="1"></ContentControl>-->
                  <TextBox Text="My text" Margin="0,0,2,0" Width="200" Height="300"/>
               </DockPanel>
            </Grid>
            <Border Grid.Row="2" BorderThickness="0,0.1,0,0" BorderBrush="Gray">
                <Grid Grid.Row="2">
                </Grid>
            </Border>
            <ContentControl Grid.RowSpan="3"
                            Grid.ColumnSpan="2"
                            HorizontalAlignment="Stretch" 
                            VerticalAlignment="Stretch" 
                            HorizontalContentAlignment="Stretch" 
                            VerticalContentAlignment="Stretch">
            </ContentControl>

        </Grid>
      
      <xctk:WindowContainer Name="xWindowContainer">
            <xctk:ChildWindow Name="ChildWindow" 
                              WindowState="Open" 
                              Caption="ChildWindowCaption" 
                              WindowStartupLocation="Center" 
                              IsModal="True">
                <ContentControl HorizontalAlignment="Stretch" 
                                VerticalAlignment="Stretch" 
                                Content="ChildContent"/>
            </xctk:ChildWindow>

            <xctk:ChildWindow Name="ChildWindowError" 
                              WindowState="Closed" 
                              Caption="ErrorWindowCaption" 
                              WindowStartupLocation="Center" 
                              IsModal="True" >
                <ContentControl HorizontalAlignment="Stretch" 
                                VerticalAlignment="Stretch" 
                                Content="ErrorContent"/>
            </xctk:ChildWindow>
        </xctk:WindowContainer>

    </Grid>
Jul 11, 2013 at 8:39 AM
See edited code in previous comment, I also put window container last now, but even though my "ChildWindowVisible" is set to Closed, I can't click on any of the control on the background. If I put WindowContainer first, and close all other views, the ChildWindow shows, and when I close it, my "ChildWindowVisible" binding is updated. I'm not sure what has changed but like I have mentioned, my previous code was working perfect for over a year until I updated to 2.0. I also noticed in your code that since 2.0 the background is no longer grayed out behind child windows.
Developer
Jul 11, 2013 at 11:55 AM
Could you attach a solution file (a sample) that could be tested on our side ?
As for the background color that is not grayed out, you can now set any color to the WindowContainer when a modal window is open in the WindowContainer, with the ModalBackgroundBrush property. The "ClickOnce app" available on https://wpftoolkit.codeplex.com/ shows it in the "WindowContainer sample" of the application.

The old version of the ChildWindow was setting a background gray to it's parent, which is not very object oriented. Now the WindowContainer contains ChildWindows and set its background color when modal windows are open. This is why the WindowContainer should be placed over background controls that should be blocked while a modal window is opened in the WindowContainer.

In the meantime, the old ChildWindow is still working, but is deprecated.
Jul 11, 2013 at 1:53 PM
I just used Nuget to downgrade back to 1.9 and everything is working perfectly again. I don't really have the time for trial and error now. I will upgrade again at 2.1 and then make the changes & if there is still a problem submit a sample.

Can the ModalBackgroundBrush be set to be semi transparent?
Developer
Jul 11, 2013 at 3:19 PM
The ModalBackgroundBrush is a Brush, so it can be semi-transparent. It's better for it to be semi-transparent so a user can se the control behind the WindowContainer.
Jan 11, 2014 at 3:23 PM
Edited Jan 11, 2014 at 3:24 PM
Hi Guys!

I’m having a similar problem with the WindowContainer/ChildWindow.
Here is a little sample snipped:
<Grid>
    <Grid>
        <TextBlock Text="MainContent" />
    </Grid>
    <xctk:WindowContainer ModalBackgroundBrush="LightGray">
        <xctk:ChildWindow Width="480"
                          Height="320"
                          IsModal="True"
                          Visibility="Collapsed"
                          WindowState="Closed">
            <TextBlock Text="Test" />
        </xctk:ChildWindow>
    </xctk:WindowContainer>
</Grid>
When starting the application, the WindowContainer is in “modal”-mode and therefore blocks the content of my MainContent grid. This happens although there is no window visible. My only window has a WindowState of Closed and the Visibility is set to Collapsed as well.

So after I start the application, the following happens:
  1. WindowContainer is created
  2. ChildWindow is created (Visibility=Visible, IsVisible=false)
  3. WindowContainer. OnVisualChildrenChanged is called and events are hooked up
  4. ChildWindow.IsModel is set to true, which triggers the IsModalChanged in the WindowContainer class. This in turn calls WindowContainer. SetModalBackground method. At this time we have a ChildWindow that is Visible (Visibility, but not IsVisible)!
  5. ChildWindow.Visibility is set to Collapsed. Although the Visibility of the ChildWindow has changed, the IsVisibleChanged event is not triggered, because IsVisible was never true.
The fix is rather simple. Since I include the WPF Toolkit via NuGet, I want stick with the original source. So I created my one ChildWindow class:
public class CustomChildWindow : ChildWindow
{
    static CustomChildWindow()
    {
        ChildWindow.WindowStateProperty.OverrideMetadata(typeof(CustomChildWindow), new FrameworkPropertyMetadata(Xceed.Wpf.Toolkit.WindowState.Closed, null, OnWindowStateChanged));
    }
    
    public CustomChildWindow()
    {
        Visibility = System.Windows.Visibility.Collapsed;
    }
    
    private static object OnWindowStateChanged(DependencyObject d, object baseValue)
    {
        var window = d as CustomChildWindow;
        if (window != null && baseValue != null)
        {
            window.Visibility = (Xceed.Wpf.Toolkit.WindowState)baseValue == Xceed.Wpf.Toolkit.WindowState.Open ? Visibility.Visible : Visibility.Collapsed;
        }
        return baseValue;
    }
}
I did not much of testing but didn’t recognise any side-effects yet. :)