3

我有一个列表框,我想更改每隔一行的颜色。我已经测试了以下代码,但颜色没有改变。我错过了什么吗?

<ListBox Height="250" BorderThickness="0" ItemsSource="{Binding Path=Results}" AlternationCount="2">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition></ColumnDefinition>
                                <ColumnDefinition></ColumnDefinition>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" FontFamily="Sagoe UI" FontSize="14" Text="{Binding FirstName, StringFormat='User: {0}'}" Padding="2"  />
                            <TextBlock Grid.Column="1" FontFamily="Sagoe UI" FontSize="14" Text="{Binding Company, StringFormat='Company: {0}'}" Padding="2" /> 
                            <TextBlock Grid.Column="2" FontFamily="Sagoe UI" FontSize="14" Text="{Binding Dept, StringFormat='Department: {0}'}" Padding="2" >                                
                            </TextBlock>
                        </Grid>                        
                    </DataTemplate>
                <ListBox.ItemTemplate>

这是我的风格以及资源和字典的结束标签

        <Style  TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="#19f39611"></Setter>
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="#19000000"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ResourceDictionary>
</UserControl.Resources>
4

1 回答 1

0

哇,Forgot我在用RadListBox,所以答案是改变打开和关闭Control Tags

 <telerik:RadListBox></telerik:RadListBox>

然后

     <Style  TargetType="{x:Type telerik:RadListBoxItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="#19f39611"></Setter>
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="#19000000"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ResourceDictionary>
</UserControl.Resources>
于 2013-05-13T17:13:59.430 回答