Search code examples
c#wpfavalondockxceed

Xceed AvalonDock 3.2 DockWidth/Height has no effect


I'm using AvalonDock(Extended.Wpf.Toolkit, free version) in an app for my employer. Setting DockWidth or DockHeight in either LayoutAnchorablePane or LayoutDocumentPane has no(visible) effect. Instead, each pane occupies an equivalent amount of space relative to its siblings(they default to 1*).

They can be resized at runtime with the built-in splitters, but that doesn't help programmatically or at design time. I've used some workarounds such as:

  • Setting DockMinWidth/DockMaxWidth to the same value, but obviously the splitters stop moving.
  • Using reflection to brute-force change the size. This is quite fragile.

Both of which are dirty hacks that I'd like to avoid.

I'm aware that this was done in the past with ResizingPanel, but it's been long since removed. See this for related information.

I've yet to find the answer in the documentation or the source code. See my answer.

Here's a simplified example demonstrating the problem.


Solution

  • This post pointed me in the right direction.

    The issue is indeed internal code. The following fixed it:

    1. Add a flag to ILayoutPositionableElement.cs. I named it ForceFixedDockSize.
    2. Implement it in LayoutPositionableGroup.cs.
    3. Inside of every override of OnFixChildrenDockLengths, check if the flag is true before setting DockWidth or DockHeight.

    I suspect the reason this behavior exists is to make default layouts look consistent. This change makes that behavior optional.

    See my fork.