ToolWindow docked to wrong DockTarget, if added before Deserializing layout, then opened

Docking/MDI for WPF Forum

Posted 2 years ago by Farris
Version: 17.2.0661
Avatar

In my application I have several different "worksheets", which basically is a different combination of open windows and land their layout. 

Each of these worksheets are serialized layouts, using the LayoutSerializer.

 

What I am now trying to accomplish, is to add a new ToolWindow to all the different layouts. To accomplish this, I create the new ToolWindow and register it with the DockSite, then I iterate through each layout, load it, call Open() on the ToolWindow, save the layout and move on to the next layout.

The issue is that the newly added window doesn't get docked in the SplitContainer beside the other existing ToolWindows, but instead gets docked in the same ToolWindowContainer as the last ToolWindow, so that it shares space with that ToolWindow, and tabs appear below the ToolWindow.

 

This code should give you an idea of what is happening:

var layoutBeforeAddingNewWindow = _layoutSerializer.SaveToString(dockSite);

var toolWindow = new ToolWindow(this.dockSite, serializationId, displayName, null, uiElement)
{
  CanAutoHide = false,
  HasOptionsButton = false
};
toolWindow.Dock(dockSite, Side.Right);

_layoutSerializer.LoadFromString(layoutBeforeAddingNewWindow, dockSite);
toolWindow.Open();
var newLayout  = _layoutSerializer.SaveToString(dockSite);

Expected result, if adding 1 window to a worksheet that already contains 1 window. Each ToolWindow in their own ToolWindowContainer:

<DockSiteLayout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SerializationFormat="All" Version="2">
<AutoHideHost />
<Content xsi:type="SplitContainer" Orientation="Horizontal" DockedSize="6,200">
<UIElement xsi:type="ToolWindowContainer" DockedSize="0,200" SelectedWindowUniqueId="3df06b6a-8a2d-4125-b331-5b70d66a4fce">
<UIElement xsi:type="ToolWindowRef" UniqueId="3df06b6a-8a2d-4125-b331-5b70d66a4fce" />
</UIElement>
<UIElement xsi:type="ToolWindowContainer" DockedSize="0,200" SelectedWindowUniqueId="0d0ce408-2232-4e18-9c11-0f560f4e0d4c">
<UIElement xsi:type="ToolWindowRef" UniqueId="0d0ce408-2232-4e18-9c11-0f560f4e0d4c" />
</UIElement>
</Content>
<ToolWindows>
<ToolWindow UniqueId="3df06b6a-8a2d-4125-b331-5b70d66a4fce" SerializationId="9f354282-c01b-464b-bad6-f058c7dc33db" ContainerDockedSize="0,200" IsOpen="true" State="Docked" />
<ToolWindow UniqueId="0d0ce408-2232-4e18-9c11-0f560f4e0d4c" SerializationId="a54db06f-f48b-47fe-bb1e-c35dc4314e8c" ContainerDockedSize="0,200" IsOpen="true" State="Docked" />
</ToolWindows>
</DockSiteLayout>

Actual, two ToolWindows inside a ToolWindowContainer:

<DockSiteLayout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SerializationFormat="All" Version="2">
<AutoHideHost />
<Content xsi:type="SplitContainer" Orientation="Horizontal" DockedSize="6,200">
<UIElement xsi:type="ToolWindowContainer" DockedSize="0,200" SelectedWindowUniqueId="33895f26-464a-43e3-89af-f5facf826e71">
<UIElement xsi:type="ToolWindowRef" UniqueId="33895f26-464a-43e3-89af-f5facf826e71" />
<UIElement xsi:type="ToolWindowRef" UniqueId="2fc4f5e2-0bbb-474f-9956-2422f6e4bc5c" />
</UIElement>
<UIElement xsi:type="ToolWindowContainer" DockedSize="0,0" />
<UIElement xsi:type="ToolWindowContainer" DockedSize="0,0" />
</Content>
<ToolWindows>
<ToolWindow UniqueId="33895f26-464a-43e3-89af-f5facf826e71" SerializationId="1f8f2f9d-294e-4bc1-8baa-24e7ad4ef47b" ContainerDockedSize="0,200" IsOpen="true" LastActiveDateTime="2017-10-05T16:36:58.028624+02:00" State="Docked" />
<ToolWindow UniqueId="2fc4f5e2-0bbb-474f-9956-2422f6e4bc5c" SerializationId="b2f4cdee-7715-4401-a1eb-a3bfb1b20c23" ContainerDockedSize="0,200" IsOpen="true" State="Docked" />
</ToolWindows>
</DockSiteLayout>

Hope you understood what I am trying to accomplish, and have a suggestion as to how to get this to work as I described.

- Farris

Comments (3)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Sorry but I'm not sure what the first pair of Save and Load calls is needed for.  If your DockSite originally has the old layout already loaded, just create the new ToolWindow and call "toolWindow.Dock(dockSite, Side.Right);" to dock it on the right side.  Then you can save that layout if you wish.  I would think that's all you need to do.

The main thing is that you want to call Dock() instead of Open() after an old layout is loaded to ensure it docks by itself on the right side.  If you only call Open() after a layout load, and without have ever opening the tool window after the layout load, it will likely attach to any already-open tool window docked on the right.  


Actipro Software Support

Posted 2 years ago by Farris
Avatar

The issue is that I have several different layouts that I wish to store this new toolwindow in. The example was simplified and only showed me adding it to one "layout", but in reality there are several. If I just dock the window, and load a layout, the newly docked window will not exist in that layout, and will be closed, thus I call "open". but when I open, it gets docked onto another toolwindow, instead of the same dockhost as it normally should

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Right, that's why I said you should load the layout, then call Dock() since that will both open it and make sure it's standalone, then save the layout.  Whenever you load a layout, it wipes out any breadcrumb data for where a tool window was.  By calling Dock() after loading the layout, you work around that.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.