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

TreeViewAdv: impossible to apply different template depending on element type ?

Let's take two different classes, one for parent, one for children :

public class ParentElement
{
 public string ParentName { get; set; }
 public IEnumerable<ChildElement> Children { get; set; }
}

public class ChildElement
{
 public string ChildName { get; set; }
}

And some ViewModel :

public class SomeViewModel
{
...
 public IEnumerable<ParentElement> Parents { get; set; }
}

I have no problem using TreeView to apply different templates for parents and children :

<sdk:TreeView x:Name="TvControl" ItemsSource="{Binding Parents}">
 <sdk:TreeView.ItemTemplate>
  <template:HierarchicalDataTemplate ItemsSource="{Binding Children}">
   <TextBlock Text="{Binding ParentName}"/>
    <template:HierarchicalDataTemplate.ItemTemplate>
     <DataTemplate>
      <TextBlock Text="{Binding ChildName}"/>
     </DataTemplate>
    </template:HierarchicalDataTemplate.ItemTemplate>
  </template:HierarchicalDataTemplate>
 </sdk:TreeView.ItemTemplate>
</sdk:TreeView>

However, HierarchicalDataTemplate seems to have a completely different behavior when used by TreeViewAdv and I just couldn't find a way to apply two different templates for Parents and Children elements.

When using the code above with TreeViewAdv instead of TreeView never brings the inner template (the one with the ChildName property) to the screen.

Is there any way to do this to reproduce with TreeViewAdv the behavior I get with TreeView ?

 


6 Replies

KR Karthick Ravichandran Syncfusion Team June 14, 2013 11:05 AM UTC

Hi Xavier,

 

Thanks for using Syncfusion products.

 

We have created a sample based on your requirement “two different templates for parent and child elements in TreeViewAdv”. Please find the attached sample.

 

Please let us know if you have any queries.

 

Regards,

Karthik



TreeViewBindingDemo_b7d82f00.zip


XN Xavier Nesi June 18, 2013 07:16 AM UTC

Hi,

 

Thank you for your answer. Unfortunately, I get the same behavior I had with my tests, meaning the child template is never used and the ChildName property never displayed.

 

I forgot to tell, maybe is it relevant, but my project is targeting Silverlight 5.



KR Karthick Ravichandran Syncfusion Team June 24, 2013 11:07 AM UTC

Hi Xavier,

 

Thanks for your update.

 

We have checked the sample with Silverlight 5 and we are unable to reproduce the problem. We have attached a sample in which we tried in Silverlight 5. Could you please modify the sample to reproduce the problem and provide the information like currently which syncfusion version you are using. This would be help for us to analyze the problem.

 

Please let us know if you have any other queries.

 

Regards,

Karthik



TreeViewBindingDemo_SL5_a4d44bba.zip


XN Xavier Nesi June 24, 2013 12:45 PM UTC

Hi,

the problem is there when I execute your code as-is. I don't have to modify anything. I just open your solution, compile and execute it, and the ChildName property is never displayed.

 

The Essential Studio release is 11.1.0.21. The Syncfusion..Tools.Silverlight dll is 11.104.0.21.

 

 

 

 

 



KR Karthick Ravichandran Syncfusion Team July 2, 2013 10:46 AM UTC

Hi Xavier,
Sorry for the inconvenience caused.
We are able to reproduce the issue “while using HierarchicalDataTemplate children element never displayed” in 11.1.0.21 version and we have created an incident #110228 for your query. Please follow up on the incident for further updates.
Please let us know if you have any queries.
Regards,
Karthik


XN Xavier Nesi July 5, 2013 08:48 AM UTC

It's working. Awesome job, thanks !


Loader.
Live Chat Icon For mobile
Up arrow icon