This is a bit old code (from RTM), but does something like what you are looking for. It checks some data on the object in the string and then sets the color of the string accordingly.
XAML:
<my:DataGrid x:Name="Grid" Grid.Row="1" Margin="5" GridlinesVisibility="None" PreparingRow="Grid_PreparingRow">
<my:DataGrid.Columns>
<my:DataGridTextBoxColumn
DisplayMemberBinding="{Binding Cheese}"
Header="Cheese"></my:DataGridTextBoxColumn>
<my:DataGridTextBoxColumn
DisplayMemberBinding="{Binding Biscuit}"
Header="Biscuit"></my:DataGridTextBoxColumn>
</my:DataGrid.Columns>
</my:DataGrid>
The code:
this.Grid.AlternatingRowBackground = null;
private void Grid_PreparingRow(object sender, DataGridRowEventArgs e)
{
CheesyClass c = e.Row.DataContext as CheesyClass;
if (c != null && c.Cheese == "cheddar")
{
e.Row.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 125, 125));
}
}
source
share