AvalonDock uses an event-driven model to notify your application of docking operations. Many events follow a cancellable Closing/Closed pattern.
DockingManager Events
Document Lifecycle
Event
EventArgs
Cancellable
Description
DocumentClosing
DocumentClosingEventArgs
✅
Raised before a document is closed. Set Cancel = true to prevent.
DocumentClosed
DocumentClosedEventArgs
—
Raised after a document has been closed.
dockManager.DocumentClosing+=(sender,args)=>{// Prompt to save changesif(HasUnsavedChanges(args.Document)){varresult=MessageBox.Show("Save changes?","Confirm",MessageBoxButton.YesNoCancel);if(result==MessageBoxResult.Cancel)args.Cancel=true;elseif(result==MessageBoxResult.Yes)Save(args.Document);}};
Anchorable Lifecycle
Event
EventArgs
Cancellable
Description
AnchorableClosing
AnchorableClosingEventArgs
✅
Before an anchorable closes.
AnchorableClosed
AnchorableClosedEventArgs
—
After an anchorable is closed.
AnchorableHiding
AnchorableHidingEventArgs
✅
Before an anchorable hides.
AnchorableHidden
AnchorableHiddenEventArgs
—
After an anchorable is hidden.
dockManager.AnchorableHiding+=(sender,args)=>{// Prevent hiding of critical panelsif(args.Anchorable.ContentId=="errorList"){args.Cancel=true;MessageBox.Show("The Error List cannot be hidden.");}};
These events are available on individual LayoutDocument and LayoutAnchorable instances:
Event
Description
Closing
Before this content closes. Cancellable.
Closed
After this content is closed.
IsActiveChanged
When the IsActive property changes.
IsSelectedChanged
When the IsSelected property changes.
EventArgs Reference
DocumentClosingEventArgs
Property
Type
Description
Document
LayoutDocument
The document being closed.
Cancel
bool
Set to true to prevent closing.
AnchorableClosingEventArgs
Property
Type
Description
Anchorable
LayoutAnchorable
The anchorable being closed.
Cancel
bool
Set to true to prevent closing.
AnchorableHidingEventArgs
Property
Type
Description
Anchorable
LayoutAnchorable
The anchorable being hidden.
Cancel
bool
Set to true to prevent hiding.
ContentDockedEventArgs
Property
Type
Description
Content
LayoutContent
The content that was docked.
ContentFloatingEventArgs
Property
Type
Description
Content
LayoutContent
The content that started floating.
Common Patterns
Save-on-Close
dockManager.DocumentClosing+=async(sender,args)=>{if(args.Document.ContentisIDocumentdoc&&doc.IsDirty){args.Cancel=true;// Prevent immediate closevarresult=awaitShowSaveDialogAsync(doc);if(result!=SaveResult.Cancel){if(result==SaveResult.Save)awaitdoc.SaveAsync();args.Document.Close();// Close after handling}}};