How to get the tool window containing another tool window at runtime ?

Docking/MDI for Windows Forms Forum

Posted 11 years ago by 7Alpha7
Version: 13.1.0311
Avatar

Hello,

for some reason the LoadToolWindowLayoutFromFile does not work  properly in my solution. I use classes derived from ToolWindow so if I let the LoadToolWindowLayoutFromFile instanciate the tool windows they're not of the desired type. So I use the OnToolWindowLayoutLoading event in order to instanciate the tool windows with the appropriate keys, so that they will exist in the dock manager before the LoadToolWindowLayoutFromFile applies the previously saved propertie.

But it does not work well : the tool window size is not applied, and if I have one tool window contained in another one, the containement hierarchy is not applied even though it's saved in the layout file.

So I wonder how to get at runtime the host object of a tool window ? I can have the DockObjectType but there's no DockObject property !

Thank you.

Comments (2)

Posted 11 years ago by 7Alpha7
Avatar

Finally I found a workaround. In fact OnToolWindowLayoutLoading is useless in my case because it seems the Actipro UI framework has already started to instanciate the tool windows from the layout file when it fires. What I did is to parse the layout file in order to instanciate the tool windows based on the key values found there, and then call LoadToolWindowLayoutFromFile.

The fact that I had not the correct layout (size, containment, etc...) was because I saved the layout too late.

Posted 11 years ago by 7Alpha7
Avatar

This piece code might help : 

        void restoreLayout() {
            if (System.IO.File.Exists(LayoutFilePath)) {
                XElement layout = XElement.Load(LayoutFilePath);
                layout.Descendants().Where(d => d.Name == "ToolWindow").Count(t => {
                    try {
                        //getToolWindow is to be written (easy)  
                        if(this.mainDockSite.getToolWindow(t.Attribute("Key").Value)==null)
                            //this call instanciates the tool window of custom type ToolWindow based on the key value
                            //in my case I have such a service to open windows from here or there
                            //do what you want  
                            MenuCommandService.invoke(t.Attribute("Key").Value);
                    }
                    catch {
                    }
                    return true;
                });
            }
            try {
                mainDockSite.LoadToolWindowLayoutFromFile(LayoutFilePath);
                //Remove unwanted tool windows instanciated by Actipro Framework if any
                //ToolWindow is the custom type 
                mainDockSite.ToolWindows.OfType<ActiproSoftware.UIStudio.Dock.ToolWindow>().Where(t => !(t is ToolWindow)).ToArray().Count(tw => {
                    tw.Dispose();
                    return true;
                });
            }
            catch {
            }
        }

[Modified 11 years ago]

The latest build of this product (v24.1.0) 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.