WPF - How do I style a row based on a binding property value?

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-06-06T20:07:22Z Indexed on 2010/06/06 20:12 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

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));
        }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf