2011-03-22 66 views
0

我有一个HierarchicalDataTemplate,它是我的TreeView的ItemSource。当TreeView显示数据时,他有一个根节点。我怎样才能删除rootnode?WPF中没有RootNode的TreeView

HierarchicalDataTemplate:

<Window.Resources> 

    <HierarchicalDataTemplate DataType="cards" ItemsSource="{Binding XPath=child::node()}"> 
     <TextBlock Text="Root"/> 
    </HierarchicalDataTemplate> 

    <HierarchicalDataTemplate DataType="category" ItemsSource="{Binding XPath=child::node()}"> 
     <TextBlock Text="{Binding [email protected]}" /> 
    </HierarchicalDataTemplate> 

    <HierarchicalDataTemplate DataType="card"> 
     <TextBlock Text="{Binding XPath=./title}" /> 
    </HierarchicalDataTemplate> 

    <XmlDataProvider x:Key="dataxml" XPath="root/cards" /> 

</Window.Resources> 

树视图:

<TreeView Name="treeViewCategory" ItemsSource="{Binding Source={StaticResource dataxml}, XPath=.}"/> 

XML:

<root> 
    <cards> 
    <category name="Categoryname"> 
     <card> 
     <title>something</title> 
     ... 
     . 
     </card> 
     <category name="SubCategory"> 
     <card> 
      <title>something else</title> 
      .. 
      ... 
     </card> 
     </category> 
    </category> 
    <card> 
     <title>text</title> 
     ... 
     .. 
    </card> 
    </cards> 
</root> 

实际视图:

o Root 
    o Categoryname 
     - something 
     o SubCategory 
      - something else 
    - text 

因为它应该是:

o Categoryname 
    - something 
    o SubCategory 
     - something else 
- text 

回答

4

只要进入一个更深一步的时候,你指定的TreeView本身的ItemsSource让你的根的孩子们成为树视图中的项目。

0

thx H.B.作品完美搭配:

<TreeView Name="treeViewCategory" ItemsSource="{Binding Source={StaticResource dataxml}, XPath=./*}" /> 

我一直试图改变XmlDataProvider的来源。 haven't想象,我应该在树视图更改路径:-(

它为什么重要?

+0

太棒了!我没有做任何与XmlDataProviders或XPath到目前为止,所以我不能提供代码,好看到你设法应用我所说的自己:)编辑:关于你添加的问题,我不知道那个抱歉,它是奇怪的不是它.... – 2011-03-22 17:01:32