Load ToolWindow from resource file

Docking/MDI for WPF Forum

Posted 14 years ago by Phillip OShea
Version: 9.2.0510
Avatar
I am looking to load a ToolWindow defined in an XAML resource file. Here is what it looks like:

<docking:ToolWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
        Title="MyWindow">
    <TextBox Text="This Window displayed correctly." />
</docking:ToolWindow>
Here is how I load the XAML file:

var myWindow = ( ToolWindow )Application.LoadComponent( new Uri( "MyWindow.xaml", UriKind.Relative ) );
Loading the control is fine, the issue arises when I attempt to Dock the window to my DockSite. Calling Dock and then Open throws an exception:

This operation is invalid since the DockingWindow has not yet been registered with a DockSite.

If I do some fancy footwork prior to calling Dock and Open, I can get it to load properly:

var temp = RootDockSite.Content;
RootDockSite.Content = myWindow;
RootDockSite.Content = temp;
My question is, how do I do this cleanly?!

Comments (2)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Philip,

There are two ways to do this:

1) Use the ToolWindow constructor that takes a DockSite instance. The parameterless one is for internal use only.

OR

2) Ensure your ToolWindow is in the ToolWindows collection of your DockSite before you dock it.

Either of those should work.


Actipro Software Support

Posted 14 years ago by Phillip OShea
Avatar
Adding the window reference to the DockSite's ToolWindow collection worked perfectly.

Thanks for your help.
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.