Customizing DockContent¶
By Ryan Rastedt, Lex Li
This page shows you how to customize DockContent
.
In this article:
Bring a DockContent to Front¶
Simply call DockContent.Activate
. This is usually used to show a tab as active tab in code.
Prevent The DockContent From Being Closed¶
You can use the OnFormClosing
method to prevent the user from closing under certain
conditions that cannot be determined until runtime (for example, showing a dialog box asking
the user if they are really sure they wish to close the tab),
public CustomContent : DockContent
{
protected override void OnFormClosing(FormClosingEventArgs e)
{
bool cancel = /* add your closing validation here */;
e.Cancel = cancel;
base.OnFormClosing(e);
}
}
To prevent a DockContent
from every being closed, you can also utilize the CloseButton
property.
You can also utilize the CloseButtonVisible
property to hide the close button when docked
in the DockPanel
control,
public CustomContent : DockContent
{
public CustomContent()
{
InitializeContent();
// Prevent this content from being closed
CloseButton = false;
// Hide the close button so the user isn't even tempted
CloseButtonVisible = false;
}
}
Note
Due to the changes in the new themes, the usage of
CloseButtonVisible
can lead to unexpected result. Please refer to
this GitHub issue
for more information.
Controlling Default Height or Width When Set to Auto-Hide¶
The property DockContent.AutoHidePortion
controls the auto-hide behaviors.
A value greater than 1 indicates a pixel size, while a value less than 1 indicates a percentage
size (as a percentage of the DockPanel
).
Dismissing Visible Auto-Hide Panel¶
Usually by double clicking the the tab of an auto-hide panel it will be dismissed. Below shows how to do it in code,
this.dockPanel.ActiveAutoHideContent = null;
Switching Among Documents¶
It is possible to add keyboard shortcuts to enable switching among document tabs, not yet part of the default code base,
Derive from
DockContent
.Override
ProcessCmdKey
.Find the next
DockContent
inDockPanel.Documents
.Call its
Activate
method.
Remove a DockContent From DockPanel¶
To release a DockContent
from DockPanel
, simply set DockContent.DockHandler.DockPanel
to null
.
dockContent.DockHandler.DockPanel = null;