Switching document causing undocks

Feb 27, 2011 at 10:43 AM

I am using AvalonDock 1.3 in a game engine project and i found a issue in regards to switching between various Documents. What happens is this on certain documents when they are being activated i am adding new toolbars ( in a similar fashion to what happens when you switch to an xml-document in Visual Studio). When we switch from a document that displays a smaller tool-bar surface area to an document that displays a larger tool-bar area, the document window undock/umounts from it's frame.

I'm not quite sure if this is something I should resolve in user-code or if it's the result of a bug that should be resolved in AvalonDock but either way I would like to get it fixed, and I was wondering if somebody could give me some insights what I am looking for exactly.

Mar 1, 2011 at 11:17 AM

Hi,

Some questions to define your problem:

 "I am adding new toolbars".

How are they built? 

Are they inserted in some layer controls? If not what happen when you insert them in a <Grid>?

Do they fire/handle events ?

Bernard from the Sofa team, an AvalonDock wrapper.

Mar 4, 2011 at 12:08 PM

Thanks for the quick reply,

My main window has 4 tool-bar trays statically defined i.e. Left, Right, Top, Bottom and in the middle the docking manager is placed. I create the tool-bars using 'code-behind' from a persistant storage medium let's say like xml. In my previous statements i mentioned adding the toolbar this is incorrect, what I actually do is simply switch the visibility from Hidden/Collapsed to Visible. However the users perception is that they are 'added','removed'

I'm not sure what you exactly mean with an layered control. But I can't host them in a grid for the reasons the tool-bars rely the 'BandIndex' to work since that index is what causes the ToolbarTray to grow/shrink when based on the visibility of the hosted child-controls. Hosting it in any other control implies the BandIndex stops working and thus it doesn't showcase the problem. Switching between document objects when the ToolbarTray is persistent in size does not trigger 'unmounts', or 'undocks'.

What events are you referring to? My data class exposes and consume some events INotifyPropertyChanged and INotifyCollectionChanged which are used respectively for:  data-binding and adjusting the menu items hosted in the tool-bars. All of them property handle their exceptions accordingly however.

 

So in summary:

1. Adding/Removing is perceptual what really happens is Visibility is toggled between Collapsed -> Visible

2. In the toolbar-tray.

3. Just your atypical events are consumed and exposed.

Mar 5, 2011 at 9:04 AM
Edited Mar 5, 2011 at 9:06 AM

Hello,

For sure there' an event in your code (or WPF event managment) that make the window floats. But no way to find out why without working on your code.

Each time this happens a new AvalonDock FloatingWindow is created and you could try to set a breakpoint in its onLoaded event hanfler.  

Hope this helps

Bernard from Sofa, an AvalonDock wrapper.

Mar 5, 2011 at 10:51 AM
Edited Mar 5, 2011 at 12:26 PM

I'll give that a shot.

On a side note I've modified the latest source code to replicated my problem. Here's the code if want to take a look: http://ul.to/lsmolj
When you activate to 'Doc3' it'll show the problem.

---edit:

Figured out the problem seems they it uses the mouse leave events to with the drag distances to determine when to convert the document window to a floating document. However it does not encounter the possibility the physical window of the control are altered for example by a ToolbarTray that get's magically bigger suddenly. Fixed the error by recording the physical coordinates of the control when mousedown, and silently ignore drag events when the coordinates have been altered ( PhysCoordMouseDown != PhysCoordMouseDrag ).