码迷,mamicode.com
首页 > Windows程序 > 详细

wpf-datagrid/listbox隔行换色

时间:2020-05-16 20:43:36      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:trigger   resource   dex   listbox   bsp   alter   red   box   property   

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隔行换色

标签:trigger   resource   dex   listbox   bsp   alter   red   box   property   

原文地址:https://www.cnblogs.com/dangnianxiaoqingxin/p/12901827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!