[Version 2.0] Crashes when hosting DockingManager in a TabControl with floating LayoutAnchorables


I have previously submitted this issue for discussion here; however, after seeing issues 12425 and 12640, this seems to be a recurring problem.

Please see attached for a test code sample.

The problem can be recreated as follows:
  1. Run code and click on to "Tab 2" in the TabControl;
  2. Undock the "Sample Tool Pane" either by selecting "Float" from the dropdown menu or by dragging it out of the DockingManager;
  3. Close the floating window (do not re-dock it first);
  4. Click on to "Tab 1" and then immediately back to "Tab 2";
  5. Click on the "Show Sample Tool Pane" button.
This will bring up an InvalidOperationException when it hits anchorable.Show() in the code-behind with the message "Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed".

A few things confuse me here:
  1. I thought LayoutAnchorables could only be "hidden" rather than properly closed;
  2. If you repeat the above steps, but leave out step 4 (the switch between the two tabs), then everything works fine and the floating window reappears;
  3. If you repeat the above steps, but re-dock the floating window before you close it (at step 3), or don't undock it in the first place, then everything works fine and the "Sample Tool Pane" reappears in its docked location.

file attachments