C1HierarchicalDataTemplate / C1TreeView problem

I am having a problem creating a ComponentOne TreeView in Silverlight (C1TreeView) with C1HierarchicalDataTemplate. Detail The tree shows only 2 levels (H1 and H2), although 3 levels are defined using HierarchicalDataTemplates, for example:

<c1:C1HierarchicalDataTemplate x:Key="H3Template">
          <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
     </c1:C1HierarchicalDataTemplate>

    <c1:C1HierarchicalDataTemplate x:Key="H2Template" ItemsSource="{Binding Path=H3Items}" ItemTemplate="{StaticResource H3Template}">
        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
    </c1:C1HierarchicalDataTemplate>

    <c1:C1HierarchicalDataTemplate x:Key="H1Template" ItemsSource="{Binding Path=H2Items}" ItemTemplate="{StaticResource H2Template}">
        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
    </c1:C1HierarchicalDataTemplate>");

      

I am using these templates in a custom TreeView (derived from C1TreeView):

 <c1:C1TreeView ... ItemTemplate="{StaticResource H1Template}">
 </c1:C1TreeView>

      

The constructor for this TreeView looks like this:

public MyTreeView(ObservableCollection<H1> h1Items)
{
    InitializeComponent();
    ItemsSource = h1Items;
}

      

Can anyone see the error in these code snippets?

thanks Dom

+1


source to share


1 answer


I am not yet familiar with the ComponentOne TreeView used, and even though you are using Silverlight, usually in WPF, when you use HierarchicalDataTemplates, you tell the template what type it is for. Subposition templates are described in a similar manner, and to what type they apply. You did not tell the data template which template to use for it ItemTemplate. This is automatically determined by the system based on the object type. This also applies when you bind a collection of items to a TreeView - you don't need to specify the ItemTemplate.

So, in your case ( local:

is the namespace defined at the top of your xaml):

<c1:C1HierarchicalDataTemplate DataType="{x:Type local:H1}" 
                               ItemsSource="{Binding Path=H2Items}">
  <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
</c1:C1HierarchicalDataTemplate>

<c1:C1HierarchicalDataTemplate DataType="{x:Type local:H2}" 
                               ItemsSource="{Binding Path=H3Items}">
  <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
</c1:C1HierarchicalDataTemplate>

<c1:C1HierarchicalDataTemplate DataType="{x:Type local:H3}">
  <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
</c1:C1HierarchicalDataTemplate>

      



And the TreeView:

<c1:C1TreeView ItemsSource="{Binding SomeH1List}"/>

      

Of course, as I said, this is specific to WPF, so it may not apply in your case.

+1


source







All Articles