两个列表框(一个列表框在另一个列表框内)的备用行颜色 [英] Alternate row colors for two listboxes (one listbox inside another)

查看:72
本文介绍了两个列表框(一个列表框在另一个列表框内)的备用行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是wpf的新手.我在另一个列表框内使用一个列表框.两个列表框内的条目应该在另一个框的下面显示,并带有其他颜色.单个列表框的项目..但是当我在一个列表框内使用另一个列表框时该怎么办?我正在使用数据模板.

因为我正在使用另一个列表框,所以项目的颜色看起来像这样:

灰色->列表框1
黄色->列表框1
灰色->列表框1
灰色->列表框2(理想情况下,此颜色应为黄色)
黄色-> listbox 2(此颜色应为灰色)

hi i''m new to wpf..i''m using a listbox inside inside another.. the items inside the two listbox should appear one below the other with alternate colors.. i could successfully set alternate row colors for items of individual listboxes.. but how do i do it when i''m using the listboxes one inside another? i''m using datatemplates.

because i''m using one listbox another the colors of the items look somewhat like this:

gray ->listbox 1
yellow ->listbox 1
gray -> listbox 1
gray ->listbox 2 (this color should be ideally yellow)
yellow ->listbox 2 (this color should be gray)

推荐答案

设置ListView的AlternateCount属性并使用触发器或绑定到ItemsControl.AlternationIndex以便设置背景颜色.

编辑对不起,已读,我改变了下面的xaml,因此内部ListView中的第一项是黄色.

Set the AlternationCount property of the ListView and use a trigger or bind to ItemsControl.AlternationIndex in order to set the background color.

Edit sorry miss read, I''ve changed the xaml below so the first item in the inner ListView is yellow.

<UserControl x:Key="test">
    <UserControl.Resources>
        <Style x:Key="itemStyle" TargetType="{x:Type ListViewItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="Grey" />
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="Yellow" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="itemStyle2" TargetType="{x:Type ListViewItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="Yellow" />
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="Grey" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <ListView AlternationCount="2" ItemContainerStyle="{StaticResource itemStyle}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ListView AlternationCount="2" ItemContainerStyle="{StaticResource itemStyle2}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</UserControl>


这篇关于两个列表框(一个列表框在另一个列表框内)的备用行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆