AlternationCount, AlternatingRowBackground 속성을 사용한 방식은 두 가지 색만 지정할 수 있습니다. 사실 두 가지 색으로도 행 간 구별은 충분하지만 좀 더 다채롭게 꾸미고 싶을 경우 AlternationCount와 DataGrid.RowStyle 사용하여 다양한 배경색을 적용할 수 있습니다.
✅ DataGrid.RowStyle 배경색 지정하기
xaml
<DataGrid ItemsSource="{Binding TempDataCollection}"
AlternationCount="3">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<Trigger Property="DataGrid.AlternationIndex" Value="0">
<Setter Property="Background" Value="Orange"/>
</Trigger>
<Trigger Property="DataGrid.AlternationIndex" Value="1">
<Setter Property="Background" Value="Red"/>
</Trigger>
<Trigger Property="DataGrid.AlternationIndex" Value="2">
<Setter Property="Background" Value="SkyBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
DataGrid.AlternationIndex 는 교대로 반복되는 행의 index입니다.
DataGrid.RowStyle 에 DataGrid.AlternationIndex 가 0, 1, 2,... 의 값일 경우에 배경색을 변경하도록 Style을 작성합니다.
AlternationCount = 4 라면 [0, 1, 2, 3] index에 해당하는 Trigger를 정의합니다.
✅ DataGrid.RowStyle 배경색 지정하기
관련 포스팅

AlternationCount, AlternatingRowBackground 속성을 사용한 방식은 두 가지 색만 지정할 수 있습니다. 사실 두 가지 색으로도 행 간 구별은 충분하지만 좀 더 다채롭게 꾸미고 싶을 경우 AlternationCount와 DataGrid.RowStyle 사용하여 다양한 배경색을 적용할 수 있습니다.
✅ DataGrid.RowStyle 배경색 지정하기
xaml
<DataGrid ItemsSource="{Binding TempDataCollection}"
AlternationCount="3">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<Trigger Property="DataGrid.AlternationIndex" Value="0">
<Setter Property="Background" Value="Orange"/>
</Trigger>
<Trigger Property="DataGrid.AlternationIndex" Value="1">
<Setter Property="Background" Value="Red"/>
</Trigger>
<Trigger Property="DataGrid.AlternationIndex" Value="2">
<Setter Property="Background" Value="SkyBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
DataGrid.AlternationIndex 는 교대로 반복되는 행의 index입니다.
DataGrid.RowStyle 에 DataGrid.AlternationIndex 가 0, 1, 2,... 의 값일 경우에 배경색을 변경하도록 Style을 작성합니다.
AlternationCount = 4 라면 [0, 1, 2, 3] index에 해당하는 Trigger를 정의합니다.
✅ DataGrid.RowStyle 배경색 지정하기