design issue?

Topics: Prism v4 - WPF 4
Nov 18, 2011 at 3:06 PM

I have the following scenario:

* few views and their associate viewmodels

* a ListBox on the left side of the window

* a ContentControl on the right side of the window.


I am trying to add a view into the ListBox (and get its specific properties to create the ListBoxItems) so the selected ListBox item will show the View into the ContentControl.

Doing this via binding(<ContentControl Content="{Binding SelectedItem, ElementName=MainRegion}"/>) doesn't work. What am I doing wrong?

Nov 18, 2011 at 3:46 PM


I tried to reproduce your problem (see the code below), and it worked OK for me:

<ListBox x:Name="Box" ItemsSource="{Binding SomeItems}"></ListBox>
<ContentControl Content="{Binding ElementName=Box,Path=SelectedItem}"></ContentControl>

You might be experiencing problems with the layout, or the kind of item displayed in the ListBox.

You might find the following article useful for your scenario, as it explains the differences between SelectedItem, SelectedValue and SelectedValuePath:

How to: Use SelectedValue, SelectedValuePath, and SelectedItem

I hope you find this helpful.

Guido Leandro Maliandi

Nov 21, 2011 at 6:52 AM


Thank you for your reply. That was exactly what I did, but the problem is:

"Specified element is already the logical child of another element. Disconnect it first.". 


Nov 21, 2011 at 12:32 PM


The problem you're experiencing might be caused by the fact that the same instance of a visual element cannot be the logical child of two elements in the tree at the same time.

The fact that you're experiencing this error might imply that you're trying to show the same content in the content control and in the list box. You could try showing only one property of your item in the list box, using the SelectedItem, SelectedValue and SelectedValuePath properties as explained in the aforementioned articles. That shuold avoid your item being the logical child of two elements at the same time.

I hope you find this helpful.

Guido Leandro Maliandi

Nov 22, 2011 at 7:02 AM



Binding just to specific properties did the trick. Thanks!