Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai i am currently using tree view below I have given my treeview code

<TreeView Background="#F9F9F9" BorderBrush="Transparent" VirtualizingStackPanel.IsVirtualizing="True"
           VirtualizingStackPanel.VirtualizationMode="Recycling"  >
           <TreeView.ItemContainerStyle>
               <!--
       This Style binds a TreeViewItem to a PersonViewModel.
       -->
               <Style TargetType="{x:Type TreeViewItem}">
                   <Setter Property="IsExpanded"   Value="{Binding IsExpanded, Mode=TwoWay}" />
                   <Setter Property="IsSelected"  Value="{Binding IsSelected, Mode=TwoWay}" />
                   <Setter Property="Visibility" Value="{Binding Visibility}"/>
                   <Setter Property="FontWeight" Value="Normal" />


                   <Style.Triggers>
                       <Trigger Property="IsSelected" Value="True" >
                           <Setter Property="FontWeight" Value="Bold" />
                       </Trigger>

                   </Style.Triggers>
               </Style>
           </TreeView.ItemContainerStyle>




           <TreeViewItem  Name="FirstTree" ItemsSource="{Binding FirstGeneration}">

               <TreeViewItem.ItemTemplate >


                   <HierarchicalDataTemplate ItemsSource="{Binding Children}"  >
                       <StackPanel Orientation="Horizontal"  >
                           <CheckBox
           Focusable="False"
           IsChecked="{Binding IsChecked}"
           VerticalAlignment="Center"
           />
                           <Image Width="16" Height="16" Margin="3,0" Source="{Binding SystemIcon}" />
                           <TextBlock Text="{Binding Name}"  />
                       </StackPanel>

                   </HierarchicalDataTemplate>
               </TreeViewItem.ItemTemplate>


           </TreeViewItem>

           <Separator BorderBrush="Black" Width="90" BorderThickness="10"/>
           <TreeViewItem  Name="Secondtree" ItemsSource="{Binding SecondGeneration}">

               <TreeViewItem.ItemTemplate >


                   <HierarchicalDataTemplate ItemsSource="{Binding Children}"  >
                       <StackPanel Orientation="Horizontal"  >
                           <CheckBox
           Focusable="False"
           IsChecked="{Binding IsChecked}"
           VerticalAlignment="Center"
           />
                           <Image Width="16" Height="16" Margin="3,0" Source="{Binding SystemIcon}" />
                           <TextBlock Text="{Binding Name}"  />
                       </StackPanel>

                   </HierarchicalDataTemplate>
               </TreeViewItem.ItemTemplate>


           </TreeViewItem>
       </TreeView>



when I use this I got both trees but in both treeitems header is empty if I write any header then inside the header I will get the actual tree. but what I need is if I get root as the XXXX name from that need to start.

What I have tried:

I tried as per what i told in above paragraph.
Posted
Comments
[no name] 3-Mar-21 13:26pm    
Store the "root" in a property and bind to that. There is one "header".
Fazi_13 4-Mar-21 3:06am    
yes i am binding FirstGeneration,Children is the observable collection.
[no name] 4-Mar-21 14:15pm    
And today it's sunny out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900