我一直致力于建立一个树视图一段时间了,现在我似乎不能得到它的输出正确.它是建立树视图如下:
1.糖果
- M&M巧克力豆
1.蔬菜
- 菠菜
1.水果
- 苹果
虽然这是正确的,但每个列表中的项目比一个更多。我错过了什么或做错了什么,它只显示每个列表的第一个项目。我现在对XML了解很多,但我不喜欢这个特定的XML是如何编写的,我觉得这是错误的,但我不是在一个地方,能够编辑它。是否有可能得到整个列表显示w/o更改的xml?如果是这样,如何?
The code is:
<TreeView x:Name="treeView" Grid.Row="1" ItemsSource="{Binding Source={StaticResource xmlFile}
,XPath=//@Name}">
<TreeView.ItemTemplate>
<DataTemplate>
<TreeViewItem Header="{Binding XPath=.}">
<StackPanel>
<TextBlock Text="{Binding XPath=..//@Foodname}"/>
</StackPanel>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
The XML for that is:
<Foods>
<UnhealthyFoods Name ="Candy"/>
<Food Foodname = "M&M's" />
</Food>
<Food Foodname = "Skittles" />
</Food>
<Food Foodname = "Starburst" />
</Food>
</UnhealthyFoods>
<HealthyFoods>
<FoodGroup1 Name ="Vegetables"/>
<Food Foodname = "Spinach" />
</Food>
<Food Foodname = "Brocolli" />
</Food>
<Food Foodname = "Greens" />
</Food>
</FoodGroup1>
</HealthyFoods>
<HealthyFoods>
<FoodGroup2 Name ="Fruits"/>
<Food Foodname = "Apples" />
</Food>
<Food Foodname = "Pears" />
</Food>
<Food Foodname = "Cherries" />
</Food>
</FoodGroup2>
</HealthyFoods>
</Foods>
1条答案
按热度按时间ippsafx71#
将文本块行更改为列表视图工作正常。不知道这是否是最好或最有效的方法,但它目前有效。欢迎更多建议