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

ItemTemplate vs. HierarchicalDataTemplate in a DiagramModel in XAML

When should I use ItemTemplate and when should I use HierarchicalDataTemplate? In your WPF samples, I see them both being used when dealing with tree layouts. I could not find any further details using the Online Documentation. Thanks for any help.

1 Reply

JR Jegan R Syncfusion Team June 25, 2010 12:38 PM UTC

Hi Tam Bui,

Thanks for your interest in Syncfusion products.

Regarding when to use ItemTemplate and when to use HierarchicalDataTemplate. ItemTemplate is a property name and HierarchicalDataTemplate is the template applied to it the content specified in ItemsSource.

Following is the code snippet is taken form BusinessObjectDataBinding sample.
















Here ItemsSource is a Collection of data which represents hierarchy of data. that is itemsSource has some collection of data, and each of these data again has collection of some other data. When an ItemTemplate is assigned to this kind of source HierarchyDataTemplate is used.

Please go through the CountrySale Object and its sub collections used in this sample.

1)ItemsSource assigned to diagramModel is an observableCollection of Country sale,
2)each CountrySale has a property called “RegionSales” which is a collection of RegionSale,
3)each RegionSale has a property called “Earnings” which is a collection of Sale.

This is what is represented in as ItemsTemplate and HierarchyDataTemplate.

1 & 2)ItemsSource assigned to diagramModel is an observableCollection of CountrySale, and each country sale has collection of RegionSale, which is represented below.

ItemsSource="{Binding Source={StaticResource myList}}"
ItemTemplate="{StaticResource dataTemplate}" >


...


Here Collection of CountrySale(mylist) is the ItemSource for diagramModel, HierarchyDataTemplate is the ItemsTemplate representing that each CountrySale has a collection of RegionSales.

2) each RegionSale has a collection of Sale.






...





Here Collection of Earnings is the ItemSource for RegionSale. HierarchyDataTemplate is the ItemsTemplate representing that, each RegionSales has a collection of Earnings.

As ItemsTemplate and HierarchyDataTemplate are general WPF concepts, they are not explained in the Online documentation, more details on these concepts can be obtained from MSDN library.

DataTemplate : http://msdn.microsoft.com/en-au/library/system.windows.datatemplate.aspx
HierarchyDataTemplate : http://msdn.microsoft.com/en-au/library/system.windows.hierarchicaldatatemplate.aspx

Please let us know if there are any concerns.

Regards,
Jegan

Loader.
Live Chat Icon For mobile
Up arrow icon