This seems like a bug, but hopefully someone has run into this before. I am setting the background color of individual cells based on the data in the underlying object to which the cell is bound. I'm doing this in the RowLoaded event in the code-behind rather than in XAML. My code looks like this:
This works great until I scroll the grid to the right. There are 30+ columns in the grid so there's a lot of real estate to cover. Once I scroll to the right and back to the left it starts losing the background colors and they return to the default. Any simple way around this or do I have to create a custom Style for the cell? If I have to go the Style route, can someone post the default cell style for the grid. I seem to remember there's no way to get at it from Blend.
Thanks.
if ((e.Row is GridViewHeaderRow) || (e.Row is GridViewFooterRow) || (e.Row is GridViewNewRow)) |
return; //we want to apply logic to data rows only |
foreach (var cell in e.Row.Cells) |
{ |
switch (cell.Column.GetValue(NameProperty).ToString()) |
{ |
case "dcPlanName": |
cell.SetBinding(GridViewCell.BackgroundProperty, new Binding("IsNextPlanNameReadOnly") { Converter = new IsTotalRowToColorConverter() }); |
break; |
case "dcLotType": |
cell.SetBinding(GridViewCell.BackgroundProperty, new Binding("IsNextLotTypeReadOnly") { Converter = new IsTotalRowToColorConverter() }); |
break; |
case "dcBldgType": |
cell.SetBinding(GridViewCell.BackgroundProperty, new Binding("IsNextBuildingReadOnly") { Converter = new IsTotalRowToColorConverter() }); |
break; |
//many more cells... |
} |
} |
This works great until I scroll the grid to the right. There are 30+ columns in the grid so there's a lot of real estate to cover. Once I scroll to the right and back to the left it starts losing the background colors and they return to the default. Any simple way around this or do I have to create a custom Style for the cell? If I have to go the Style route, can someone post the default cell style for the grid. I seem to remember there's no way to get at it from Blend.
Thanks.