Category / Section
How to change the caption alignment of dock window in WPF DockingManager?
1 min read
The Caption elements (Header content, CloseButton, AutoHidePin button, MenuButton… etc) of Dock window will be arranged in the DockPanel of DockHeaderPresenter and the FlowDirection will be Left to Right by default in WPF DockingManager. So, the order of the elements will be Header content, MenuButton, AutoHide pin button and CloseButton.
Default arrangement of header elements in Dock Window:
This order can be changed by setting the FlowDirection of the DockPanel to Right to Left. The following code example demonstrates the same,
C#
private void UpdateFlowDirectionofHeader(FlowDirection direction) { foreach (FrameworkElement child in DockingManager.Children) { if (DockingManager.GetDockHeaderPresenter(child) != null) { // Code to change the Dock window header elements DockHeaderPresenter presenter = DockingManager.GetDockHeaderPresenter(child); if (presenter != null) { DockPanel panel = VisualUtils.FindDescendant(presenter as Visual, typeof(DockPanel)) as DockPanel; if (panel != null) { panel.FlowDirection = direction; } } } else { if(DockingManager.GetState(child) == DockState.Document) { // Code to change the MDI window Header elements MDIWindow window = VisualUtils.FindAncestor(child as Visual, typeof(MDIWindow)) as MDIWindow; if(window != null) { DocumentHeader header = window.Template.FindName("PART_DocumentHeader", window) as DocumentHeader; if(header != null) { header.FlowDirection = direction; } } } } } }
The following screenshot shows the output of the above code,