Restore Autohidden ToolWindowContainers

Docking/MDI for WPF Forum

Posted 12 years ago by Mitsuhiro Kanazawa
Version: 11.2.0552

I wrote the following test code to try autohide and dock (restore) ToolWindowContainers. My test code creates three ToolWindowContainers by “Create Windows” button, and “Auto Hide Windows” button hides two of them. The purpose of this code is to enlarge one of ToolWindowContainers as necessary, and “Restore Windows” button is intended to restore the layouts of three ToolWindowContainers.

<Window x:Class="AutoHideDockingExample.MainWindow"
        Title="MainWindow" Height="502" Width="617">

    <DockPanel LastChildFill="True">
        <ToolBarTray DockPanel.Dock="Top">
                <Button ToolTip="Create Windows" Name="buttonCreateWindows" Content="Create Windows" Click="buttonCreateWindows_Click" />
                <Button ToolTip="AutoHide Windows" Name="buttonAutoHideWindows"  Content="Auto Hide Windows" Click="buttonAutoHideWindows_Click" />
                <Button ToolTip="Restore Windows" Name="buttonRestoreWindows" Content="Restore Windows" Click="buttonRestoreWindows_Click" />                

    <docking:DockSite x:Name="dockSite">
            <docking:SplitContainer Orientation="Vertical">


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ActiproSoftware.Windows.Controls.Docking;

namespace AutoHideDockingExample {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {

        private void buttonCreateWindows_Click(object sender, RoutedEventArgs e) {
            DockSite ds = new DockSite();
            SplitContainer sc = new SplitContainer();
            sc.Orientation = Orientation.Vertical;
            ToolWindow gtw; 
            int numOfInnerTabs = 5;
            // Top ToolWindowContainer
            ToolWindowContainer tc1 = new ToolWindowContainer();
            tc1.Name = "tc1";
            ToolWindow tw1 = new ToolWindow();
            tw1.CanClose = false;
            tw1.Name = "tw1";
            tw1.Title = "tw1";            

            // Middle ToolWindowContainer
            ToolWindowContainer tc2 = new ToolWindowContainer();
            tc2.Name = "tc2";

            for(int i = 0; i < numOfInnerTabs; i++) {
                gtw = new ToolWindow();
                gtw.Title = "tw2-" + i.ToString();

            // Bottom ToolWindowContainer
            ToolWindowContainer tc3 = new ToolWindowContainer();
            tc3.Name = "tc3";
            ToolWindow tw3 = new ToolWindow();
            tw3.Title = "tw3";
            tw3.CanClose = false;


            ds.Content = sc;

            DocumentWindow documentWindow = new DocumentWindow(dockSite, "Name", "Title", new BitmapImage(new Uri("", UriKind.Relative)), ds);
            // Activate the document

        private void buttonAutoHideWindows_Click(object sender, RoutedEventArgs e) {
            if(dockSite.ActiveWindow == null)

            SplitContainer sc = (SplitContainer)((DockSite)((DocumentWindow)dockSite.ActiveWindow).Content).Content;
            ToolWindowContainer twc;

            for(int i = 0; i < sc.Children.Count; i++) {

                twc = (ToolWindowContainer)sc.Children[i];                


        private void buttonRestoreWindows_Click(object sender, RoutedEventArgs e) {            

            if(dockSite.ActiveWindow == null)

            SplitContainer sc = (SplitContainer)((DockSite)((DocumentWindow)dockSite.ActiveWindow).Content).Content;
            ToolWindowContainer twc;
            for(int i = 0; i < sc.Children.Count; i++) {              
                twc = (ToolWindowContainer)sc.Children[i];                


“Restore Windows” button calls “Dock” method for each ToolWindowContainer, but three ToolWindowContainers are not restored. I also tried to use DockSiteLayoutSerializer, but it didn’t work as well.

My question is how to restore the layout of ToolWindowContainers after Autohide. Or, if you have different ways to enlarge one of ToolWindowContainer and restore the layout, please let me know.

I'm a beginner C# programmer, so I'm sorry if this is a simplistic question.



Comments (2)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Mitsuhiro,

In your XAML you really shouldn't put a container in a docking layout unless you specifically put a docking window inside it. Also, you shouldn't create windows by creating containers either. Containers are automatically created by our code from programmatic calls from methods like ToolWindow.Dock, so they are created as needed. Because of this the way you handle the other buttons isn't recommended because you shouldn't rely on specific containers being there as they are dynamically created and destroyed as the program runs.

About your original question: you want to do a similar process to what you are doing now to restore the windows, but you want to work with the ToolWindows instead of the ToolWindowContainers. On each ToolWindow you want to restore you should call Dock with no parameters to return it to its previously docked state.

Actipro Software Support

Posted 12 years ago by Mitsuhiro Kanazawa

I rewrote my code, and applied ToolWindows instead of ToolWindowContainers. Now it works perfect.

Thank you very much for your support.


The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.