Got an error when open a hidden ToolWindow

Docking/MDI for Windows Forms Forum

Posted 13 years ago by Buddhist
Avatar
I used SaveToolWindowLayoutToFile(...) to store my tool windows layout.
But I got an error when I opened a hidden ToolWindow. Below was what I did.

I closed a tool window, then quit the whole app and stored the layout.
I can see some stuffs were added into the layout.xml,
<Hidden>
<ToolWindow Key=" ...
...
</ToolWindow>
</Hidden>

Then, I opened the app and wanna bring up that tool window again, I got this,
System.ArgumentException: The Guid specified for the tool window has already been registered for another tool window.

I can't figure out what happened because I am very sure that the GUID was unique.
So I'm wondering if this is a bug of UIStudio.
My version is 2.0.72.0, XP SP2...

[Modified at 10/15/2006 09:51 PM]

Comments (7)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hmm... yes it sounds like it might be a bug but we haven't heard of it before. Could you find a way to reproduce it and send over a small sample project that shows it? Then we can debug it and get it fixed for you. Or even if you can tell us how to repro it in our sample that is fine.

I tried reproing it in sample but it worked ok for me.


Actipro Software Support

Posted 13 years ago by Buddhist
Avatar
I'm trying to repro it.
Only one tool window steadily got this problem, but others were ok.
Thx.
Posted 13 years ago by Buddhist
Avatar
Oh, I figure out what happened.
Because I only wanna create tool windows on demand, not at startup, so, if I create the tool window just after loaded the layout configuration, and it just existed in that configuration, I got the problem. :-(
it's in below sequence,
1. Load layout;
2. Create tool window;
3. Check if it already exsits by means of DockManager.ToolWindows.Contains(string key);
4. Exception;

How to handle this scenario? Should I keep track of tool windows by use of DockManager.ToolWindows.Contains(ToolWindow value)? I'm afraid so.

Besides, can you tell what info will be stored in the file created SaveLayoutToFile()?
Personally, I believe if users can control what info should be recorded, everything should be much better.

Thx.
Posted 13 years ago by Buddhist
Avatar
I did further investigation.
It looks like I have to create all tool windows before loading the layout setting, since LoadUserSettingsForMainForm() is going to automatically create empty tool windows, if doesn't do so.

This means I can't create tool windows totally on demand, and have to create all instances before loading layout, doesn't it? Except I don't use the Save/Load layout function.
:(
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Actually there are several nice built-in mechanisms for handling all this.

First make sure you use ToolWindow.Key. You can use that instead of actual ToolWindow references to track your tool windows and see if any are loaded.

But more importantly, you can set DockManager.AutoCreateToolWindowsForLayoutLoad to false to prevent tool windows from automatically being created. The nice thing about that is that if DockManager.UnknownToolWindowStatePreservationEnabled is set to true, it will cache the layout information for the tool window key that was in the layout but not created. Then when you do create it later, it merges that cached layout data back into the tool window you made.

Also, there is a DockManager.WindowInitializing event that lets you initialize a tool window right before the first time it is displayed. Check out the help topic on window lifecycles for more info on that. It allows for lazy-load of tool window contents.


Actipro Software Support

Posted 13 years ago by Buddhist
Avatar
Product Version: UIStudio v2.0.73

Cool!

DockManager.AutoCreateToolWindowsForLayoutLoad did cache the layout info.
But it looks like haven't reloaded the cached info when I created the tool windows later.
I only created the tool windows and activated them. But the location was wrong.
Did I miss sth?

Thx.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It will cache them based on the ToolWindow.Key. So ensure that it is the same as what is in the layout.

If you don't think that it is working correctly then please email us a small sample project showing the problem. Thanks!


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.