This project has moved and is read-only. For the latest updates, please go here.

ChildWidow bug or how to set Template of ChildWindow

Mar 29, 2012 at 11:50 AM
Edited Mar 29, 2012 at 11:51 AM

Hi, I'm trying to write my own ControlTemplte for ChildWindow, and when I trying to set root element of ControlTemplate like Grid, StackPanel, DockPanel  it gives me an Exception 'Object reference not set to an instance of an object.'

Example

            <extToolkit:ChildWindow x:Name="Popup" WindowStartupLocation="Center" IsModal="True">
                <extToolkit:ChildWindow.Template>
                    <ControlTemplate TargetType="{x:Type extToolkit:ChildWindow}">
                        <Grid></Grid>
                    </ControlTemplate>
                </extToolkit:ChildWindow.Template>
            </extToolkit:ChildWindow>

Is it a bug, or I'm using it wrong?

Mar 29, 2012 at 3:58 PM

Thank you for submitting this issue.  I created the Issue #17727 to solve this problem.  The problem is that the ChildWindow assumes some controls with specific names exist.  If these controls aren't found, an exception is thrown.

 

Right now, to make your template work, here it the minimum you must set:

 

<ControlTemplate TargetType="{x:Type xctk:ChildWindow}">
  <Grid x:Name="Root">
    <Grid x:Name="PART_WindowRoot" />
  </Grid>
</ControlTemplate>

Apr 17, 2012 at 12:55 PM

thanx, it helps but when I'm trying to redesign CloseButton with name = "PART_CloseButton" button began do not close the popup

example

                <ControlTemplate TargetType="extToolkit:ChildWindow">
                    <Grid x:Name="Root">
                        <Grid.Resources>
                            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
                        </Grid.Resources>
                        <Grid x:Name="PART_WindowRoot" Background="#221E1F">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="50"/>
                                </Grid.ColumnDefinitions>
                                <Border Grid.Column="0" Background="Yellow" x:Name="PART_DragWidget"/>
                                <Button Grid.Column="1" Background="Red" x:Name="PART_CloseButton"/>
                            </Grid>
                            <ContentPresenter Grid.Row="1"/>
                        </Grid>
                    </Grid>
                </ControlTemplate>

Apr 17, 2012 at 2:13 PM

I created the issue #17868 to investigate on this and see if the default behavior should be changed.  Basically, a click on "PART_CloseButton" will set the ChildWindow.WindowState to WindowState.Closed.  However, it will not hide the popup.

 

This was done by the following trigger in the default control template:

<ControlTemplate.Triggers>
   <Trigger Property="WindowState" Value="Closed">
      <Setter Property="Visibility" Value="Collapsed" />
   </Trigger>
</ControlTemplate.Triggers>