Restore Autohidden ToolWindowContainers

Docking/MDI for WPF Forum

Posted 7 years ago by Mitsuhiro Kanazawa
Version: 11.2.0552
Avatar

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"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
        xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
        Title="MainWindow" Height="502" Width="617">

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

    <docking:DockSite x:Name="dockSite">
        <docking:SplitContainer>           
            <docking:SplitContainer Orientation="Vertical">
                <docking:Workspace>
                    <docking:TabbedMdiHost>
                        <docking:TabbedMdiContainer>                           
                        </docking:TabbedMdiContainer>
                    </docking:TabbedMdiHost>
                </docking:Workspace>              
            </docking:SplitContainer>
        </docking:SplitContainer>
     </docking:DockSite>
    </DockPanel>
</Window>

 

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() {
            InitializeComponent();
        }

        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";            
            tc1.Items.Add(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();
                tc2.Items.Add(gtw);            
            }

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

            sc.Children.Add(tc1);
            sc.Children.Add(tc2);
            sc.Children.Add(tc3);

            ds.Content = sc;

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

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

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

            for(int i = 0; i < sc.Children.Count; i++) {
                if(!sc.Children[i].GetType().ToString().Contains("ToolWindowContainer"))
                    continue;

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

                if(!twc.Name.Contains("tc2"))
                    twc.AutoHide();               
            }
        }

        private void buttonRestoreWindows_Click(object sender, RoutedEventArgs e) {            
            dockSite.LastActiveDocument.Activate();

            if(dockSite.ActiveWindow == null)
                return;            

            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];                
                twc.Dock();
            }
        }
    }
}

 

“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.

Regards,

Mitsuhiro

Comments (2)

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

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 7 years ago by Mitsuhiro Kanazawa
Avatar

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

Thank you very much for your support.

Mitsuhiro

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.