This is a migrated thread and some comments may be shown as answers.
Alternate Row Color
3 Answers 127 Views
This is a migrated thread and some comments may be shown as answers.
Duncan
Top achievements
Rank 1
Duncan asked on 05 Jun 2012, 03:45 PM
This works with the standard ListBox:
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
         
        <Grid.Resources>
            <Style  TargetType="{x:Type ListBoxItem}">
                <Style.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="LightYellow"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="LightBlue"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
         
         
        <ListBox ItemsSource="{Binding Path=Items}"
                      AlternationCount="2"/>
         
    </Grid>
</Window>


This does not work with the RadListBox:
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
         
        <Grid.Resources>
            <Style  TargetType="{x:Type t:RadListBoxItem}">
                <Style.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="LightYellow"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="LightBlue"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
         
         
        <t:RadListBox ItemsSource="{Binding Path=Items}"
                      AlternationCount="2"/>
         
    </Grid>
</Window>


Any ideas?

3 Answers, 1 is accepted

Sort by
0
Dani
Telerik team
answered on 06 Jun 2012, 08:11 AM
Hi Duncan,

Please, try moving you custom implicit style to the App.xaml resources as it won't get applied from Grid.Reosurces. Or, you can try setting it explicitly via the ItemContainerStyle property of the RadListBox control.

Hope this helps.

Regards,
Dani
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
ben
Top achievements
Rank 1
answered on 01 Jun 2015, 08:51 PM

I'm not having any luck getting the suggestions to work, I've moved the style all over the place and the only thing I've been able to accomplish is hiding all of the items in the RadListBox.

Is it possible to have alternating row colors in a RadListBox, and if so can one provide a working example?

 

Thanks!

0
Geri
Telerik team
answered on 04 Jun 2015, 02:09 PM
Hello Ben,

Attached you can find a sample project where the style is set explicitly via the ItemContainerStyle property of RadListBox and the rows are colored differently according to the set Background value.

Please, take a look at the project and let us know if you have any further inquiries.

Regards,
Geri
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Duncan
Top achievements
Rank 1
Answers by
Dani
Telerik team
ben
Top achievements
Rank 1
Geri
Telerik team
Share this question
or