Autohiding tool windows and ItemsSource binding

Docking/MDI for WPF Forum

Posted 15 years ago by wpf.acp
Version: 9.1.0500

I have a problem with auto hiding tool windows. The problem may or may not be caused by your docking code but as I have never come across a similar issue I tend to believe there is a connection.

Please consider two dockable/autohide tool windows. Both host the same ListBox. The only difference between them is the way ItemsSource is bound. Now imagine two TextBlocks in the workspace, each bound to SelectedItem of one of the ListBoxes. When run all works as expected. Changing the selection in each of the ListBoxes reflects in their corresponding TextBlocks. The problem arises when one unpins the tool windows. One of the ListBoxes loses the current selection while the other one maintains it even when hidden.

ItemsSource of the first ListBox is bound to a property using ElementName (this one works) and the other one is bound relying on DataContext which is set previously on a parent element (this one does not work).

Both ListBoxes are essentially bound to the same collection but because of the difference in data binding, they behave differently.

I am sending the sample project that reproduces the issue to your support mail.

Thanks for looking into this issue.

Comments (2)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
I believe the problem here is that when a tool window moves around to auto-hide mode for instance, it logical and visual parents are changed.

So if you use a binding with ElementName, you are binding directly to a control no matter where it is. Logical and visual parent changes won't

affect the binding.

When you don't bind with ElementName and therefore bind via inherited DataContext, your binding is relying on the DataContext being passed down

the tree. In this scenario, when the parent is changed, the data context changes (although to the same thing), but this rebuilds the items and

wipes out the selection. If you put a button on your window and in its handler print out info about the _listbox while its in auto-hide mode,

you'll see it still has 2 items (because it did reattach to the data context) but the selection cleared.

Actipro Software Support

Posted 15 years ago by wpf.acp
Ok, thanks! Your explanation makes sense. As a rule of thumb a special consideration needs to be taken into account when dealing with tool windows and binding to avoid unnecessary headaches.
The latest build of this product (v24.1.2) 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.