wpf-datagrid/listbox隔行换色
Posted dangnianxiaoqingxin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wpf-datagrid/listbox隔行换色相关的知识,希望对你有一定的参考价值。
listbox
<ListBox AlternationCount="2" > <ListBox.Resources> <Style TargetType="ListBoxItem"> <Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="Red"/> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Background" Value="Black"/> </Trigger> </Style.Triggers> </Style> </ListBox.Resources> <ListBoxItem>1</ListBoxItem> <ListBoxItem>2</ListBoxItem> <ListBoxItem>3</ListBoxItem> <ListBoxItem>4</ListBoxItem> <ListBoxItem>5</ListBoxItem> </ListBox>
Datagrid
<DataGrid AlternationCount="2"> <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="#FFE4DDB3" /> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Background" Value="#FFF2F2F2" /> </Trigger> </Style.Triggers> </Style> </DataGrid.RowStyle> </DataGrid>
以上是关于wpf-datagrid/listbox隔行换色的主要内容,如果未能解决你的问题,请参考以下文章