Reputation: 1027
I have a Dictionary<String, Int32[]>
which is named someDict
. Keys are binding to ListBox.ItemsSource
. Values of ListBox.SelectedItem
must to be binding to ComboBox.ItemsSource
. How to do it?
<ListBox x:Name="listBox" Grid.Column="0" ItemsSource="{Binding Path=someDict.Keys}"/>
<ComboBox x:Name="comboBox" Grid.Column="1" VerticalAlignment="Top"
ItemsSource="{Binding ElementName=comboBox, Path=SelectedItem}"/>
Upvotes: 1
Views: 2659
Reputation: 728
You have to make some changes to your XAML
.
ItemsSource
of your ListBox
should be the whole Dictionary
. To diplay Key
values use an ItemTemplate
Modify the ItemsSource
of a ComboBox
<ListBox x:Name="listBox" Grid.Column="0" ItemsSource="{Binding Path=someDict}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ComboBox x:Name="comboBox" Grid.Column="1" VerticalAlignment="Top" ItemsSource="{Binding ElementName=listBox, Path=SelectedItem.Value}"/>
Upvotes: 4