Articles in this section
Category / Section

How to set alternate row background in MultiColumn TreeViewAdv?

2 mins read

This article describes how to set alternate row background for multiple column TreeViewAdv control.

AlternationCount and AlternationIndex

Use AlternationCount and AlternationIndex properties to specify the appearance for alternating item containers.

The following code example demonstrates the same.

XAML

<syncfusion:TreeViewAdv AlternationCount="2" MultiColumnEnable="True">
            <syncfusion:TreeViewAdv.Resources>
                <Style TargetType="syncfusion:TreeViewItemAdv">
                    <Style.Triggers>
                        <Trigger Property="AlternationIndex"  Value="0">
                            <Setter Property="Background" Value="LightBlue" />
                        </Trigger>
                        <Trigger Property="AlternationIndex"  Value="1">
                            <Setter Property="Background" Value="LightGray" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </syncfusion:TreeViewAdv.Resources>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 1" Description="Description about Item 1"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 2" Description="Description about Item 2"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 3" Description="Description about Item 3"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 4" Description="Description about Item 4"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 5" Description="Description about Item 5"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 6" Description="Description about Item 6"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 7" Description="Description about Item 7"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 8" Description="Description about Item 8"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader ="Item 9" Description="Description about Item 9"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewItemAdv>
                <syncfusion:TreeViewItemAdv.Header>
                    <local:TreeModel TreeHeader="Item 10" Description="Description about Item 10"/>
                </syncfusion:TreeViewItemAdv.Header>
            </syncfusion:TreeViewItemAdv>
            <syncfusion:TreeViewAdv.Columns>
                <syncfusion:TreeViewColumnCollection>
                    <syncfusion:TreeViewColumn Width="200" Header="Name"
       DisplayMemberBinding="{Binding Path=Header.TreeHeader, RelativeSource={RelativeSource AncestorType={x:Type syncfusion:TreeViewItemAdv}}}"/>
                    <syncfusion:TreeViewColumn Width="200" Header="Description"
       DisplayMemberBinding="{Binding Path=Header.Description, RelativeSource={RelativeSource AncestorType={x:Type syncfusion:TreeViewItemAdv}}}"/>
                </syncfusion:TreeViewColumnCollection>
            </syncfusion:TreeViewAdv.Columns>
        </syncfusion:TreeViewAdv>

C#

public class TreeModel
    {
        private string header;
        public string TreeHeader
        {
            get { return header; }
            set { header = value; }
        }
 
        private string description;
        public string Description
        {
            get { return description; }
            set { description = value; }
        } 
    }

 

The output for the above code is shown below:

row with alternative background in wpf multicolumn treeview.

Figure 1: Rows with alternative background in TreeViewAdv control 


Conclusion

I hope you enjoyed learning about how to set alternate row backgrounds in MultiColumn TreeView control for WPF.

You can refer to our WPF TreeView feature tour page to learn about its other groundbreaking feature representations. You can also explore our WPF TreeView documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied