My DataTable
contains values of composite types for each column, the goal is for use both to dispaly the Value
Property and style it by State
Property
public class PairData
{
public string Value { get; set; }
public int State { get; set; }
}
it is possible to config the datagrid menualy like:
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Column1.Value}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Column1.State}" Value="1">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
but i want to generate columns dinmicly using AutoGenerateColumns="True"
Is there a way to bind all columns for 'Value' Property? Perhaps something like:
<DataGrid ItemsSource="{Binding Path=Source}" >
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Foreground" Value="Black" />
<Setter Property="TextBlock.Text" Value="{Binding Value}"/>
</Style>
</DataGrid.CellStyle>
</DataGrid>
I got an error:
System.Windows.Data Error: 40 : BindingExpression path error: 'Value' property not found on 'object' ''DataRowView' (HashCode=15375790)'. BindingExpression:Path=Value; DataItem='DataRowView' (HashCode=15375790); target element is 'DataGridCell' (Name=''); target property is 'Text' (type 'String')