grimpows
Dynamic Binding for DataGrid WPF
following this article : https://paulstovell.com/dynamic-datagrid/
i'm stuck at the "Rendering basic columns in a DataGrid" section.
I dont really see where i should put that code in a MVVM practice.
should i create the entire datagrid in the VM ?
should i trigger on some ItemsSource updated event in the code behind ? ...
fixed with help of https://stackoverflow.com/questions/64687172/how-to-autogenerate-datagrid-columns-for-collection-of-child-type-from-collectio
first i do create a Data class that contain my Records :
record :
property
in your VM you can instanciate your prop with
60 replies
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)
</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)
1 replies