WPF - How do I style a row based on a binding property value?
- by Nick
Hey!
So I am trying to bind a collection of objects (IList<) to a WPF datagrid. I would like to make the row background a different color if the 'artist' property is null or empty. I am checking the value stored at the property on the LoadingRow datagrid event. Currently my implementation seems to style all of the rows with an empty or null 'artist' property correctly. The problem is that is also styles the rows where the property is not null or empty in some cases. So some rows are given the red background even though the rows 'artist' property is not null. Can anyone tell me why this could be??
Here is the LoadingRow event:
private void trackGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
Track t = e.Row.DataContext as Track;
if (String.IsNullOrEmpty(t.Artist))
{
e.Row.Background =
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 125, 125));
}
}