I have two listboxes which I both bind to the same selected index. The reason for this is that in the first one I enter some things and then specify to which property it belongs:
For example:
- Bird
- Dog
- Fish
Can be combined with
- House
- Garder
- Living room
Everything works fine when each item occurres only once but when I have something like
- Dog House
- Fish House
Then the synchronization isn’t working.
I have tried IsSynchronizedWithCurrentItem="True" but this gave me an exception when I opened the page.
This is the code for the listboxes
<ListBox BorderBrush="{x:Null}" Grid.Column="0" HorizontalAlignment="Stretch"
ItemsSource="{Binding Animals}"
SelectedItem="{Binding SelectedListBoxItem,Mode=TwoWay}"
SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}"
ItemTemplate="{StaticResource ListBoxItemTemplate}"/>
<ListBox BorderBrush="{x:Null}" Grid.Column="1" HorizontalAlignment="Stretch"
ItemsSource="{Binding Places}"
SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}"
ItemTemplate="{StaticResource ListBoxItemTemplate}"/>
Just to not cause some confusion about the datatemplate
<DataTemplate x:Key="ListBoxItemTemplate">
<TextBlock Text="{Binding Name}" Height="15"/>
</DataTemplate>
EDIT:
When I want to set it to true I see in the designer the following message
[Selector_IsSynchronizedWithCurrentItemCannotSetToTrue]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient ....
The number of items in both listboxes is always the same.
The exception (web page error) is the generic
Line: 1
Error: Unhandled Error in Silverlight Application Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
Instead of adding always the same item from the treeview I create a new from the selected item which is then passed into the listbox. This way you have to different items but at the end I only care about their Id (placeID) so that it doesn’t matter…
Hope this helps someone…