我有一個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
太棒了!我沒有做任何與XmlDataProviders或XPath到目前爲止,所以我不能提供代碼,好看到你設法應用我所說的自己:)編輯:關於你添加的問題,我不知道那個抱歉,它是奇怪的不是它.... – 2011-03-22 17:01:32