We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Treeview programatically change node colour

I have a treeview which load data via a binding to a nodes collection.

Currently, all the nodes are the same colour. How can I change individual nodes depending on the node item bound to that node? Preferably leaving the styling in the XAML

1 Reply

DR Durga Rajan Syncfusion Team April 3, 2017 12:39 PM UTC

Hi Richard, 
 
Thank you for contacting Syncfusion Support. 
 
We have analyzed your query and prepared sample to meet your requirement. We can achieve your requirement by customizing the ItemTemplate of TreeView. Kindly make use of below codes, 
 
Code Snippet: [XAML] 
  
                    <syncfusion:TreeViewAdv.ItemTemplate> 
 
                <HierarchicalDataTemplate ItemsSource="{Binding SubItems}"> 
 
                 <TextBlock Text="{Binding Header}" Foreground="{Binding ForeColor}" /> 
 
                </HierarchicalDataTemplate> 
                 
 
            </syncfusion:TreeViewAdv.ItemTemplate> 
  
  
Code Snippet: [C#] 
 
Model Root1 = new Model() { Header = "Root1", ForeColor = new SolidColorBrush(Colors.Red) }; 
 
Screenshot : 
 
 
 
Please download the sample from the following location. 
 
Sample: TreeViewTest 
 
Regards, 
Durga S. 


Loader.
Up arrow icon