I've got a WPF datagrid bound to a list of parts and I need alternating row colors. The parts can also be part of a group, in which case the entire group needs to be the same color. Kind of like:
Part 1, group 1 - White background
Part 2, group 2 - Blue background
Part 3, group 3 - White background
Part 4, group 3 - White background
Part 5, group 4 - Blue background
Part 6, group 4 - Blue background
Part 7, group 5 - White background
The alternation of color must be based on groups, not simply by every other row. I have tried using grid.ItemContainerGenerator in the codebehind when the source collection is updated, but this does not work. ItemContainerGenerator.ContainerFromIndex() always returns null at this time, I suppose because the grid is still updating, I don't know. How can I do this?