Alternate Row Color

4 posts, 0 answers
  1. Duncan
    Duncan  avatar
    13 posts
    Member since:
    Mar 2011

    Posted 05 Jun 2012 Link to this post

    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?
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 06 Jun 2012 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. ben
    ben avatar
    5 posts
    Member since:
    Jul 2007

    Posted 01 Jun 2015 in reply to Dani Link to this post

    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!

  5. Geri
    Admin
    Geri avatar
    60 posts

    Posted 04 Jun 2015 Link to this post

    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
Back to Top