none
WPF Treeview hide root node RRS feed

  • Question

  • Hi Guys, how can i hide the root node in WPF treeview?

    Using the below HierarchicalDataTemplatethis is the output:

      <XmlDataProvider x:Key="questions" XPath="Questions" />
            <HierarchicalDataTemplate x:Key="rootTemplate" >
                <HierarchicalDataTemplate.ItemsSource>
                    <Binding XPath="child::*" />
                </HierarchicalDataTemplate.ItemsSource>
                <StackPanel Orientation="Horizontal" >
    
                    <CheckBox Name="checkBoxTree"  Checked="TreeView_Checked" Unchecked="checkBoxTree_Unchecked" 
                              Margin="0,4,0,0"  Style="{DynamicResource CheckBoxStyle1}"/>
                    
                    <TextBlock Text="{Binding XPath=@Name, Mode=TwoWay}" />               
                    <TextBlock >                               
                               <Hyperlink NavigateUri="{Binding XPath=@WebSite}" RequestNavigate="Hyperlink_RequestNavigate">  
                                   <TextBlock Text="{Binding XPath=@WebSite}" /> 
                               </Hyperlink>    
                    </TextBlock>               
                </StackPanel>
            </HierarchicalDataTemplate>

    Treeview:

    <TreeView Name="TreeViewer" HorizontalAlignment="Left" Height="220" Margin="10,116,0,0" Grid.Row="1" 
                          VerticalAlignment="Top" Width="700" Visibility="Collapsed"  FontSize="15" 
       ItemsSource="{Binding Source={StaticResource questions}}" ItemTemplate="{StaticResource rootTemplate}" 
                          BorderThickness="3" >

    <?xml version="1.0" encoding="utf-8" ?>
    <Questions>
     
    
        <Question1 Name="Recherche du driver">
          <Type Name="Windows X" >
            <Solution Name ="1.Look at the Table"/>
            <Solution Name ="2.Fix the problem by yourself"/>
            <Solution Name ="Solved: YES"/>
            <Solution Name ="Solved : NO"/>
            
            <Solution WebSite ="http://www.test.eu/"/>
            
          </Type>
          <Type Name="Mac OS X" >
            <Solution Name ="1.Look at the Table"/>
            <Solution Name ="2.Fix the problem by yourself"/>
            <Solution Name ="Solved: YES"/>
            <Solution Name ="Solved : NO"/>
    
          </Type>
        </Question1>
    </Questions>

    Thank you for your support!

    Karthik



    • Edited by FF_DAPI Wednesday, November 13, 2013 3:15 PM edited
    Wednesday, November 13, 2013 2:35 PM

Answers

  • Solution found:

    Xpath problem. <XmlDataProvider x:Key="questions" XPath="Questions/*" />

    • Marked as answer by FF_DAPI Wednesday, November 13, 2013 3:16 PM
    Wednesday, November 13, 2013 3:15 PM

All replies