I am populating a Datagrid from a datatable. The datatable is created at runtime, and there are an unknown number of rows and columns. The column headers are created when the datatable is loaded. If there is an empty cell in the Datatable I would like it highlighted.
I looked at the answer here. But it does not work, It only highlights a cell in a single column, and they are binding to a column. Which I can't do.
My code:
<DataGrid x:Name="dataGrid" ItemsSource="{Binding DGLines}">
<DataGrid.Columns>
<DataGridTextColumn>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Background" Value="LightGreen"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
The empty cells value is actually null. I'm not sure if that's the problem.
What is the correct style to highlight an empty cell in any column?