I have a simple DataGrid, that looks like this
<DataGrid ItemsSource="{Binding GridList}">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="Auto" />
<Setter Property="Background" Value="Black" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding ID}" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
But now I want to add another TextBlock
in DataTemplate
that looks like this
<TextBlock Grid.Column="1" Text="{Binding Values["Entity1"]}" />
Or
<TextBlock Grid.Column="1" Text="{Binding Values.Entity1}" />
But I cannot get it working, actually I do not know how to create the Last one so it is going to work
The model for the List looks like this
class ListModel {
public int ID {get;set;}
public IDictionary<string, string> Values {get;set;}
}
Of course I can replace the IDictionary to something else but what?
Actually I figured it out, I changed the ListModel to
class ListModel {
public string this[string key] { get{return _values[key];} set{_values[key]=value;}}
public int ID{get;set;}
public IDictionary<string,string> _values = new Dictionary<string,string>();
}
And the XAML to
<TextBlock Grid.Column="1" Text="{Binding [Entity1]}" />