【发布时间】:2016-10-15 14:10:21
【问题描述】:
我有一个有两个集合的类,我需要在我的树中显示它。
class Test
{
ObservableCollection<Test> ReplacementOptions {get; set;}
ObservableCollection<Test> Given {get; set;}
public String Name {get; set;}
}
目前我只知道如何使用 ReplacementOptions 来创建它:
<TreeView Grid.Row="1" x:Name="DefaultEquipmentTreeView" ItemsSource="{Binding SelectedUnit.DefaultEquipment}" PreviewMouseRightButtonUp="OnPreviewMouseRightButtonDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding ReplacementOptions}" >
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<i:Interaction.Behaviors>
<xmlEditor:BindableSelectedItemBehavior SelectedItem="{Binding SelectedDefaultEquipment, Mode=TwoWay}" />
</i:Interaction.Behaviors>
</TreeView>
如何使用 MVVM 在树中递归地显示两个集合?
例子:
如您所见,每个测试都有 2 个测试集合。
Test1 //Name
--Replacement //Replacements. for the collection name
-- Test2 //Then that lists each Test Name in that collection
--Replacements //then that Collection has both Collections... etc
--Test4
--Given
--Given // Given
--Test3
--Replacements(empty collection)
--Given(empty collection)
【问题讨论】:
-
它们将如何呈现,按顺序呈现,或以类似联合的方式呈现?
-
我用一个例子更新了帖子。
-
抱歉,不能用你的第三个代码块来解决我的问题,它看起来是递归的,但是......这棵树到底应该做什么/帮助你?
-
我有需要查看的数据结构。看看这个类,它是如何拥有两个自己类型的集合的。直到运行时我才知道大小。