MDI Document Layout
Dock can display documents as classic MDI windows inside a document dock. In this mode documents become movable, resizable windows with minimize, maximize, and restore states.
Enable MDI mode
Set the layout mode on a document dock:
var documents = new DocumentDock
{
LayoutMode = DocumentLayoutMode.Mdi
};
If you prefer fluent setup:
factory.DocumentDock(out var documents)
.WithLayoutMode(DocumentLayoutMode.Mdi);
Arrange documents
Document docks expose commands for common MDI layout operations:
documents.CascadeDocuments?.Execute(null);
documents.TileDocumentsHorizontal?.Execute(null);
documents.TileDocumentsVertical?.Execute(null);
documents.RestoreDocuments?.Execute(null);
The commands use the dock’s current visible bounds to compute layouts.
Document state and bounds
Documents implement IMdiDocument and store their window bounds and state:
MdiBoundsstores the normal window rectangle.MdiStatetracksNormal,Minimized, andMaximizedstates.MdiZIndexcontrols stacking order.
These values are serialized with the layout so windows restore to their previous positions.
MDI control customization
The Avalonia controls expose additional properties for theming:
MdiDocumentControlforwardsIconTemplate,HeaderTemplate,ModifiedTemplate,CloseTemplate, andCloseButtonThemeto each window.MdiDocumentWindowexposesDocumentContextMenu,MdiState, andIsActivefor styling or interaction.
To customize the layout algorithm, provide an IMdiLayoutManager implementation. It can be assigned on MdiDocumentControl.LayoutManager (which the default template forwards to MdiLayoutPanel):
var mdiLayoutManager = new MyMdiLayoutManager();
mdiDocumentControl.LayoutManager = mdiLayoutManager;
For details on the built-in layout helpers and defaults see MDI layout helpers.
Notes
- The document header contains a drag handle that starts docking operations when you drag it outside the MDI surface.
- When a document is maximized the stored bounds remain unchanged so restore returns to the previous size.
- Managed floating windows reuse
MdiDocumentWindowinsideManagedWindowLayerwhenDockSettings.UseManagedWindowsis enabled. See the Managed windows guide.
For an overview of all guides see the documentation index.