style triggers for alternating rows don't always update when scrolling virtualized WPF Datagrid

前端 未结 1 807
忘了有多久
忘了有多久 2021-01-24 13:51

There are a few questions similar to this on SO, I\'ve read this one and another I can\'t find the link for, but none of them seem to have a solution that\'s applicable.

相关标签:
1条回答
  • 2021-01-24 14:42

    That's the nature of virtualization. Only a set number of UI objects are actually rendered, and when you scroll you are changing the DataContext behind those objects.

    So in your case, Rows are created and given a background color. When you scroll, the DataContext behind those rows change, so a data object might be in a row that was given Color A at a certain scroll position, or be in a row that was assigned color B at another scroll position.

    Most of the time the alternating colors are only there to help identify what columns are in what row so it doesn't matter if they change, however if you want to maintain a consistent background color for the rows you will probably have to add something to the data object and base your background color off that property. That way when you scroll and the DataContext changes, the row color will also change.

    0 讨论(0)
提交回复
热议问题