What's the correct DataTrigger binding for DataContext properties? I have a DataGrid which is bound like this:
XAML:
<DataGrid x:Name="dataGrid" Grid.Row="4" Grid.ColumnSpan="2"
ItemsSource="{Binding}"
CellStyle="{StaticResource RowStateStyle}"
>
</DataGrid>
In .cs the grid is bound to a DataTable, hence the DataContext for a cell is DataRowView, containing Row as a property:
// DataTable containing lots of rows/columns
dataGrid.DataContext = dataTable;
Edit:
Refering to ASh's solution I edited the style and put in Triggers for Unchanged and Modified:
<Style x:Key="RowStateStyle" TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DataContext.Row.RowState,
RelativeSource={RelativeSource Self}}" Value="Unchanged">
<Setter Property="Foreground" Value="Green" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=DataContext.Row.RowState,
RelativeSource={RelativeSource Self}}" Value="Modified">
<Setter Property="Foreground" Value="Yellow" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Content.Text,
RelativeSource={RelativeSource Self}}" Value="test">
<Setter Property="Foreground" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
Triggering on Content.Text works perfectly fine, so does Unchanged. However when I modify a cell (thus DataRowState = Modified), nothing happens and the color stays green. Any solution?