0

Only the the first level tree node is visible without any child, but my CollectionViewSource has groups with atleast one item. How can i bind the to child's ItemSource to Items property within each group.

<HierarchicalDataTemplate x:Key="myTemplate" >
    <!-- Level 1 -->
    <WrapPanel>
        <CheckBox IsChecked="True" Margin="2,2,2,2" ></CheckBox>
        <TextBlock Text="{Binding Name}" Margin="2,2,2,2" ></TextBlock>
    </WrapPanel>
    <HierarchicalDataTemplate.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Items}">
            <!-- Level 2 -->
            <WrapPanel>
                <CheckBox IsChecked="True" Margin="2,2,2,2" ></CheckBox>
                <TextBlock Text="{Binding Name}" Margin="2,2,2,2" ></TextBlock>
            </WrapPanel>
            <DataTemplate>
                <WrapPanel>
                    <CheckBox IsChecked="{Binding IsChecked}" Margin="2,2,2,2" ></CheckBox>
                    <TextBlock Text="{Binding Name}" Margin="2,2,2,2" ></TextBlock>
                </WrapPanel>
            </DataTemplate>
        </HierarchicalDataTemplate>
    </HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>

<TreeView x:Name="TreeViewClaims" Grid.Row="1" Grid.Column="0" Margin="2,2,2,2" BorderThickness="0"
    ItemsSource="{Binding GroupByView.View.Groups}" 
    ItemTemplate="{StaticResource myTemplate}">
</TreeView>
Alex David
  • 585
  • 1
  • 11
  • 32

1 Answers1

0

If all items should be displayed the same way you only have to specify one HierachicalDataTemplate and set the ItemsSource (property where your children are stored).

<HierarchicalDataTemplate x:Key="myTemplate"
                          ItemssSource="{Binding Items}"
                          TargetType="{x:Type FirstLevelViewModel}">
<WrapPanel>
    <CheckBox IsChecked="True" Margin="2,2,2,2" ></CheckBox>
    <TextBlock Text="{Binding Name}" Margin="2,2,2,2" ></TextBlock>
</WrapPanel>
</HierarchicalDataTemplate>

If you want a different view for each level you can implement a different viewmodel for each level and use the TargetType property in your HierachicalDataTemplate. The template will be automaically applied for rendering the viewmodel. But you cant use a HierachicalDataTemplate like you did in your first post.

Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51
  • I want checkbox of all nodes except the terminal child to selected by default and for the terminal child, it will be decided by the binded property. That why i have to explicitly define template for each level. – Alex David Mar 20 '14 at 09:08