Reputation: 102945
The question is simple: how do I achieve stripe colors for WPF data grids like this:
This modifies each row to contain gray background, now I need to improve this:
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="#aaa" />
</Style>
Upvotes: 2
Views: 3367
Reputation: 257
Use AlternatingRowBackground property of the DataGrid to have the code automatically stripe the rows for you. The Brush color you select will be the alternating color. You can further customize this with AlternationCount property to set how often you want the rows to be alternated (the default is 2 which is most likely what you are looking for based on that picture, but you can always select 3 or more if you want to go hog wild).
<DataGrid AlternatingRowBackground="WhiteSmoke" AlternationCount="2" />
Upvotes: 9
Reputation: 1197
You can use the AlternatingRowBackground property of the DataGrid for that.
Upvotes: 9
Reputation: 30127
Use alternate row color property AlternatingRowBackground to have different color for alternating rows
Upvotes: 3