ChildWindow

Derives from Xceed.Wpf.Toolkit.Primitives.WindowControl

Starting with version 2.0, ChildWindow (and MessageBox) is derived from WindowControl and no longer manages its parent’s background or the positioning of itself based on its parent’s size. The old version of ChildWindow will remain available, but obsolete.

A WindowContainer should now be used to contain these controls. It provides an area where WindowControl-derived controls (ChildWindow or MessageBox controls) can be displayed. This is particularly interesting in an XBAP application where windows can't be popped up. In this case the WindowContainer can be sized to fit the application and the window-like control can be moved around in the WindowContainer.

The WindowContainer derives from Canvas and positions its children according to its size. Many actions performed on its children are managed by the WindowContainer (movement and positioning, resizing, visibility, modal, and mouse click). This will restrict the WindowControl movements and resizing to the WindowContainer’s size.

When no Width and Height are specified in the WindowContainer, its DesiredSize will be the size of its biggest child.

Show the dialog by calling ChildWindow.Show or by setting the ChildWindow.WindowState property.
childwindow.jpg

<xctk:WindowContainer>
  <xctk:ChildWindow WindowBackground="Blue"
                    Left="75"
                    Top="50"
                    Width="275"
                    Height="125"
                    WindowState="Open">
    <TextBlock Text="This is a Child Window" Padding="10"/>
  </xctk:ChildWindow>

  <xctk:ChildWindow WindowBackground="Green"
                    Left="175"
                    Top="125"
                    Width="275"
                    Height="125"
                    WindowState="Open">
    <TextBlock Text="This is another Child Window" Padding="10"/>
  </xctk:ChildWindow>

  <xctk:MessageBox Caption="MessageBox"
                   Text="This is a MessageBox"/>
</xctk:WindowContainer>

Properties

Property Description
Caption Gets or sets the caption of the ChildWindow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
CaptionForeground Gets or sets the foreground color of the caption text. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
CaptionIcon Gets or sets the caption icon. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
CaptionShadowBrush Gets or sets the brush of the caption's shadow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
CloseButtonStyle Gets or sets the style of the ChildWindow's close button. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
CloseButtonVisibility Gets or sets the visibility of the ChildWindow's close button. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
DesignerWindowState Gets or sets the state of the ChildWindow in the designer.
DialogResult Gets or sets a value indicating whether the ChildWindow was accepted or canceled
FocusedElement Gets or sets the FrameworkElement that currently has focus.
IsActive Gets or sets whether the control is active. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
IsModal Gets or sets a value indicating whether the ChildWindow is modal.
Left Gets or sets the left position of the ChildWindow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
Top Gets or sets the top position of the ChildWindow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowBackground Gets or sets the background color of the ChildWindow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowBorderBrush Gets or sets the BorderBrush of the ChildWindow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowBorderThickness Gets or sets the window's border thickness. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowInactiveBackground Gets or sets the window's inactive background. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowOpacity Gets or sets the opacity of the ChildWindow. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowStartupLocation Gets or sets the startup location of the ChildWindow.
WindowState Gets or sets the current state of the ChildWindow.
WindowStyle Gets or sets the window's style. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
WindowThickness Gets or sets the window's thickness. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)

Events

Event Description
CloseButtonClicked Raised when the Close button is clicked. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
Closed Raised when the ChildWindow is closed.
Closing Raised when the ChildWindow is closing.
HeaderDragDelta Raised as the mouse changes position when a header has logical focus and mouse capture. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
HeaderIconClicked Raised when the header icon is clicked. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
HeaderIconDoubleClicked Raised when the header icon is double-clicked. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
HeaderMouseLeftButtonClicked Raised when the header is clicked using the left mouse button. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
HeaderMouseLeftButtonDoubleClicked Raised when the header is double-clicked using the left mouse button. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)
HeaderMouseRightButtonClicked Raised when the header is clicked using the right mouse button. (Inherited from Xceed.Wpf.Toolkit.Primitives.WindowControl)

Methods

Method Description
Close Closes the ChildWindow and sets the WindowState to Closed.
OnApplyTemplate Overridden. Invoked whenever application code or internal processes call ApplyTemplate.
Show Shows the ChildWindow and sets the WindowState to Open.


Support this project, check out the Plus Edition.
---

Last edited Jun 10 at 3:54 PM by dlafontaine, version 15

Comments

BoucherS Jul 2 at 12:05 PM 
Hi jyys98, please use a discussion tab to elaborate on your problem. Also, can you please add a code snippet to reproduce the issue ? Thanks.

jyys98 Jul 1 at 10:53 AM 
Well, I've got a problem when I'm trying to use this control. It displayed well in VS, but just disappeared when my program is in progress. NEED HELP!!

BoucherS Jul 4, 2013 at 11:56 AM 
Issue https://wpftoolkit.codeplex.com/workitem/17859 already exists for this request.

parhs Jun 30, 2013 at 1:09 PM 
What sucks and always did in most implementations like this is that hitting TAB you can change stuff at background and screw the application.

emartin Dec 13, 2012 at 7:56 PM 
Please, use DISCUSSIONS tab for community support

admdev Dec 11, 2012 at 7:33 PM 
I am not sure if these comments are seen by anybody, but I am using this control and I just had question.

I am using it in one of my Windows and I am trying to set focus on the only textbox it contains, but I cannot get it to focus.

Any help would be greatly appreciated.

Thanks.

emartin Nov 29, 2012 at 1:47 PM 
Please, use DISCUSSIONS tab for community support.

Jay_Kidd Nov 28, 2012 at 10:59 AM 
regarding hooking up the close button to an event handler (re:garrafote) using the 1.8.0 build, I've also had some trouble. Clicking on the button does nothing (it doesn't close), I think this might be out of the box behaviour (by design)? Instead you can listen for the event using a routed event handler. Example here:
' add to constructor
Me.AddHandler(Button.ClickEvent, New RoutedEventHandler(AddressOf RoutedEvent))

Private Sub RoutedEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
' check if this is the close button being pressed
If DirectCast(e.OriginalSource, Button).Name = "PART_CloseButton" Then
Me.Visibility = Windows.Visibility.Collapsed
End If
End Sub

Any insights / recommendations on how we should be implementing this would be useful! :)

harbnazha Nov 20, 2012 at 10:53 AM 
Hello,

I tried using this control. i put this in the xaml:
<xctk:ChildWindow x:Class="MKISModule.MkisInformationModule.Views.StakeholderViews"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d" Width="300" Height="300">

<Grid Margin="10" x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="First Name:" Margin="2" VerticalAlignment="Center" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding FirstName}" Margin="2" VerticalAlignment="Center" />

<TextBlock Grid.Row="1" Text="First Name:" Margin="2" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding LastName}" Margin="2" VerticalAlignment="Center" />
</Grid>
</xctk:ChildWindow>


and the backcode just had the InitializeComponent(); in the constructor.

and in another usercontrol i added this to a button click:
var c = new StakeholderViews();
c.Show();

but nothing happened. it didn't show me anything. Please advise.
Thanks,
Nazha

garrafote Jul 16, 2012 at 5:30 AM 
How to set a close button click event handler?

cbordeman Jun 20, 2011 at 8:00 PM 
P.S. FocusedElement is a FrameworkElement, not a string currently.

cbordeman Jun 20, 2011 at 7:59 PM 
Can the new "FocusedElement" be changed to a string? The DataTemplate may change or the element to focus may not be created yet so no FrameworkElement is available.

thieum22 Jun 2, 2011 at 8:35 PM 
New property : FocusedElement : Get or Sets the name of the control that will get focus on child window opening.

thieum22 Apr 5, 2011 at 7:33 PM 
Be aware that the child window will be part of the visual tree where it is declared. If you declare it in a grid, it's size may have an impact on the rest of the grid depending on the settings you have in this grid. You can set span properties or isolate the child window to avoid any side effect on the main grid when it opens.

bpell Jan 19, 2011 at 4:27 AM 
Very nice. I can see this as being a very useful control.