列表框的更改颜色更改

时间:2013-05-13 16:17:11

标签: c# wpf xaml

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

<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>

这是我的风格和resoruces和词典的结束标签

        <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>

1 个答案:

答案 0 :(得分: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>