C
C#2y ago
grimpows

Binding to Dictionary in WPF with a binding KEY

hello i have a very specific problem related to WPF : i have a listbox with itemsSource <ListBox ItemsSource="{Binding someKeyValuePairList}">
</ListBox> i could show the Key with <ListBox ItemsSource="{Binding someKeyValuePairList}"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <TextBlock Margin="2" Text="{Binding Key}" /> .... </ListBox> and i also have some Dictionary where i want to access value who contain a ViewModel with the Key i have <ListBox ItemsSource="{Binding someKeyValuePairList}"> <ListBox.ItemTemplate> <DataTemplate> <Grid> ---> if i hardcode the key this working <ContentControl Content="{Binding DataContext.SomeDictionaryWithObject[test].ViewModel, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/> ----> if i want to use the Value {Binding Key} this dont work ... <ContentControl Content="{Binding DataContext.SomeDictionaryWithObject[{Binding Key}].ViewModel, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/> </Grid> </DataTemplate>
</ListBox.ItemTemplate> </ListBox> (for information i also have setted a DataTemplate for my ViewModel so the content control render the associated view)
0 Replies
No replies yetBe the first to reply to this messageJoin