Create Visual Studio-like Docking Windows in WPF
Tags: csharp, beginners, docker, programming
Published: 2019-06-24 11:16:34

---
title: Create Visual Studio-like Docking Windows in WPF
published: true
description: This blog explains about creating a docking windows in WPF with Visual Studio's docking behavior. This is achieved using Sycnfusion WPF Docking Manager.
canonical_url: https://www.syncfusion.com/blogs/post/create-visual-studio-like-docking-windows-in-wpf.aspx
tags: csharp, beginners, docker, programming
---
As .NET developers, we have all worked in <a href="https://visualstudio.microsoft.com/">Visual Studio</a> and at some point may have wondered about the docking windows that hold the Solution Explorer, Code Window, Toolbox, and others. Visual Studio-style docking windows allow you to resize, move, and change the behavior of windows to create a layout that suits various development models. The Syncfusion <a href="https://www.syncfusion.com/wpf-ui-controls/docking">docking manager</a> allows users to create their own layouts by just dragging and dropping windows to the desired positions. Users can persist the layout with built-in serialization options. Every part of the docking windows can be customized, and a variety of built-in themes are included for changing the window appearances.

In this blog post, we will demonstrate how to create Visual Studio-like docking windows in a WPF application and customize their layouts.
<h2>Overview</h2>
The docking manager component lets you add Visual Studio-style docking windows and tabbed document interfaces to your application. It allows interactive dragging of docking windows around the screen to make them float over any location. As in Visual Studio, the docking manager offers different kinds of windows:
<ul>
 	<li>Dock</li>
 	<li>Float</li>
 	<li>Document</li>
 	<li>Autohidden</li>
</ul>
<h2>Getting Started with The Docking Manager</h2>
Configure the WPF application for the docking manager by following these steps:
<ol>
 	<li>In Visual Studio, create a new WPF project. For our demonstration, we are going to name it <strong>VisualStudioLikeDockWindow</strong>.</li>
 	<li>Install <a href="https://www.nuget.org/packages/Syncfusion.Tools.WPF/">Syncfusion.Tools.WPF</a> NuGet package to the project.</li>
 	<li>Add the XML namespace <strong><a href="http://schemas.syncfusion.com/wpf">http://schemas.syncfusion.com/wpf</a></strong> with a prefix in XAML. Here we used <strong>syncfusion</strong> as a prefix for the namespace.
```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf" >
</Window>
```
</li>
 	<li>Add <strong>DockingManager</strong> to the window using the namespace prefix.
```xml
<syncfusion:DockingManager x:Name="SyncDockingManager">
</syncfusion:DockingManager>
```
</li>
 	<li>Add child controls to create your docking window. The child controls can be any <strong>FrameworkElement</strong>. In this example, shown in the next step, we have added four <strong>ContentControl</strong> as children.</li>
 	<li>Set headers for the docking windows using the attached property <strong>Header</strong> of the docking manager.
```xml
<syncfusion:DockingManager x:Name="DockingManager" >
 
<ContentControl Name="Output” syncfusion:DockingManager.Header="Output">
 
<!-- Output docking window -->
 
</ContentControl>
 
<ContentControl Name="SolutionExplorer"syncfusion:DockingManager.Header="Solution Explorer">
 
<!-- Solution Explorer docking window -->
 
</ContentControl>
 
<ContentControl Name="Properties" syncfusion:DockingManager.Header="PropertiesWindow">
 
<!-- Properties docking window -->
 
</ContentControl>
 
<ContentControl Name="Toolbox" syncfusion:DockingManager.Header="Toolbox">
 
<!-- Toolbox docking window -->
 
</ContentControl>
 
</syncfusion:DockingManager>
```
</li>
 	<li>Set the <strong>VisualStyle</strong> of the application to one of the visual styles. Here we set it to <strong>VS2010</strong>. A complete list of the available styles can be found in <a href="https://help.syncfusion.com/wpf/dockingmanager/styling-and-templates">our documentation</a>.
```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        syncfusion:SkinStorage.VisualStyle="VS2010"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf" >
</Window>
```
</li>
</ol>
<figure>
  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2019/06/Docking-Windows-before-arranging.png" alt="Docking Windows before arranging" style="width:100%">
  <figcaption>Docking Windows before arranging</figcaption>
</figure>

<h2>Arranging and Docking Windows</h2>
Like the Toolbox and Solution Explorer windows in Visual Studio, customers expect to dock windows at any side of a container. The docking manager allows users to dock the windows anywhere in the docking manager by setting the <strong>SideInDockMode</strong> attached property.

The docking manager also introduces the attached property <strong>TargetNameInDockedMode</strong> to decide whether a window is to be docked relative to the docking manager or another docking window. Arrange the child windows as tabbed windows, by using the tabbed option in SideInDockMode.

<strong>DesiredHeightInDockedMode</strong> and <strong>DesiredWidthInDockedMode</strong> help control the size of the docking windows.

Here we are going to add tabs to the Solution Explorer and Output children of <strong>DockingManager</strong>.
```xml
<syncfusion:DockingManager x:Name="DockingManager" >
 
<ContentControl Name="Output" syncfusion:DockingManager.Header="Output"
                syncfusion:DockingManager.SideInDockedMode="Bottom"
                syncfusion:DockingManager.DesiredHeightInDockedMode="150">
 
<!-- Output docking window -->
 
</ContentControl>
 
<ContentControl Name="FindResults" syncfusion:DockingManager.Header="Find Results"
                syncfusion:DockingManager.SideInDockedMode="Tabbed"
                syncfusion:DockingManager.TargetNameInDockedMode="Output" >
 
<!-- Find Results docking window -->
 
</ContentControl>
 
<ContentControl Name="ErrorList" syncfusion:DockingManager.Header="Error List"
                syncfusion:DockingManager.SideInDockedMode="Tabbed"
                syncfusion:DockingManager.TargetNameInDockedMode="Output" >
 
<!-- Error List docking window -->
 
</ContentControl>
 
<ContentControl Name="SolutionExplorer"
                syncfusion:DockingManager.Header="Solution Explorer"
                syncfusion:DockingManager.SideInDockedMode="Right"
                syncfusion:DockingManager.DesiredWidthInDockedMode="200">
 
<!-- Solution Explorer docking window -->
 
</ContentControl>
 
<ContentControl Name="ClassView" syncfusion:DockingManager.Header="Class View"
                syncfusion:DockingManager.SideInDockedMode="Tabbed"
                syncfusion:DockingManager.TargetNameInDockedMode="SolutionExplorer" >
 
<!-- Class View docking window -->
 
</ContentControl>
 
 
<ContentControl Name="Properties" syncfusion:DockingManager.Header="Properties Window"
                syncfusion:DockingManager.SideInDockedMode="Tabbed"
                syncfusion:DockingManager.TargetNameInDockedMode="SolutionExplorer" >
 
<!-- Properties docking window -->
 
</ContentControl>
 
<ContentControl Name="Toolbox" syncfusion:DockingManager.Header="Toolbox"
                syncfusion:DockingManager.State="Dock"
                syncfusion:DockingManager.DesiredWidthInDockedMode="180">
 
<!-- Toolbox docking window -->
 
</ContentControl>
 
</syncfusion:DockingManager>
```
<figure>
  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2019/06/Docking-Windows-after-arranging.png" alt="Docking Windows after arranging" style="width:100%">
  <figcaption>Docking Windows after arranging</figcaption>
</figure>

<h2>Configure Document Windows</h2>
Configure document states to build a Visual Studio-like tabbed document. Add document windows just as you would docking windows. Additionally, set the value of the <strong>UseDocumentContainer</strong> property as <strong>True</strong> and set <strong>Document</strong> as the value of the <strong>State</strong> property of child windows.
```xml
<syncfusion:DockingManager  x:Name="SyncDockingManager" UseDocumentContainer="True">
<ContentControl Name="MainWindowXAMLView" syncfusion:DockingManager.Header="MainWindow.xaml" syncfusion:DockingManager.State="Document">
 
</ContentControl>
 
<ContentControl Name="MainWindowCSView" syncfusion:DockingManager.Header="MainWindow.xaml.cs" syncfusion:DockingManager.State="Document">
</ContentControl>
 
</syncfusion:DockingManager>
```
<figure>
  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2019/06/Visual-Studio-Like-Docking-Windows.png" alt="Visual Studio-Like Docking Windows" style="width:100%">
  <figcaption>Visual Studio-Like Docking Windows</figcaption>
</figure>

<h3>Tab groups</h3>
The docking manager allows you to create a group of tabbed documents similar to Visual Studio. Tab groups split the workspace and allow users to work with two or more open documents. This can be created in horizontal and vertical directions and allow documents to be shuffled between them. <strong>New Horizontal Tab Group</strong> and <strong>New Vertical Tab Group</strong> options are available in the context menu of every document and will be displayed when users right-click the tab header of a document.
<figure>
  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2019/06/Document-Tab-Group.png" alt="Document Tab Group" style="width:100%">
  <figcaption>Document Tab Group</figcaption>
</figure>

Create tab groups programmatically by passing the child window as an argument to the <strong>CreateHorizontalTabGroup</strong> or <strong>CreateVerticalTabGroup</strong> methods.
```csharp
DockingManager.CreateHorizontalTabGroup(MainWindowXAMLView);

DockingManager.CreateVerticalTabGroup(MainWindowXAMLView);
```
<h2>Float Docking or Document Windows</h2>
We can drag and float the docking and document windows over any location on the screen. By default drag the docking windows by clicking and dragging the title of the window. But document windows can be dragged by clicking and dragging the tab header of the corresponding document once <strong>IsVS2010DraggingEnabled</strong> is enabled. Alternatively, docking and document windows can float by double-clicking on window captions. To enable this float functionality on double-clicking a document, set the <strong>EnableDocumentToFloatOnDoubleClick</strong> property of the docking manager as <strong>True</strong>.

Float windows in the docking manager are pop-ups with size restrictions. To overcome this limitation, you can configure the float window as a WPF window by enabling <strong>UseNativeFloatWindow</strong>.
```xml
<syncfusion:DockingManager  x:Name="SyncDockingManager" UseDocumentContainer="True" UseNativeFloatWindow="True" EnableDocumentToFloatOnDoubleClick="True" IsVS2010DraggingEnabled="True">
</syncfusion:DockingManager>
```
The docking manager provides dock hints that indicate a valid drop location when users are dragging the float window. When a window is about to be docked, a dock preview will be displayed to show where the window will be placed.
<figure>
  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2019/06/Floating-Window.png" alt="Floating Window" style="width:100%">
  <figcaption>Floating Window</figcaption>
</figure>
Whenever you’re in a situation to create non-floatable windows, you can use the <strong>CanFloat</strong> attached property of the docking manager to restrict the docking and document windows.
```xml
<ContentControl Name="MainWindowXAMLView" syncfusion:DockingManager.State="Document"
             syncfusion:DockingManager.CanFloat="False">
                 
</ContentControl>
```
<h2>Close and Pin Dock Windows</h2>
If you don’t want any more windows in your application, docking windows can be closed by clicking the <strong>Close</strong> button in their title bar. Close the document windows by selecting their corresponding tab and using the common <strong>Close</strong> button at the right of the document container. Every document can have a separate <strong>Close</strong> button in their corresponding tab by setting the <strong>DocumentCloseButtonType</strong> property as <strong>Individual</strong>.
```xml
DockingManager.DocumentCloseButtonType = CloseButtonType.Individual;
```
To restore a closed window to your application, pass the specific child window to <strong>RestoreElement</strong>.
```xml
DockingManager.RestoreElement(SolutionExplorer);
```
The docking manager also allows users to pin docking windows to the edges of the work area. Pinning docking windows automatically hides them to any side of the screen and their names appear on tabs at the edges of the container. To use the pinned windows again, just mouse over a tab and that window will slide back into view. The <strong>Pin</strong> button in the title bar lets you pin and re-dock the window to the view.
<figure>
  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2019/06/Autohidden-Window.png" alt="Auto-hidden Window" style="width:100%">
  <figcaption>Auto-hidden Window</figcaption>
</figure>

<h2>Layout Persistence</h2>
The docking manager allows you to save the docked window arrangements automatically while closing the application by enabling <strong>PersistState</strong>. It also lets users save the current docking layout of the application with <strong>SaveDockState</strong>. When you want to load the saved layout back into your application, it can be restored by using <strong>LoadDockState</strong>.
```csharp
DockingManager.PersistState = true;

// To save the current layout of DockingManager
DockingManager.SaveDockState();

// To load the last saved layout of DockingManager
DockingManager.LoadDockState();
```
<h2>Conclusion</h2>
Now you can create Visual Studio-style layouts for your applications and customize your window layouts to best fit various development workflows.

In this blog, we covered just the basic features of the docking manager. For more information and details about other advanced topics, please refer to our <a href="https://help.syncfusion.com/wpf/dockingmanager/overview">documentation</a>, where you will see code samples for features not covered here. Other features you can learn about include handling window state changes, dockability, multiple document interfaces, and much more.

Feel free to share your feedback in the comments below. You can also contact us through our <a href="https://www.syncfusion.com/forums">support forum</a> or <a href="https://www.syncfusion.com/support/directtrac/">Direct-Trac</a>. We are happy to assist you!

The sample code for the features explained in this blog post can be downloaded from this <a href="https://github.com/SyncfusionExamples/wpf-visual-studio-docking-windows-demo">GitHub repository</a>.