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