您好我有一个树视图,我试图深入了解2级。
第二级未显示
这是我的VM中的类和集合
public class BuildTree
{
public int Id { get; set; }
public string Groups { get; set; }
public IEnumerable<myAreas> Areas { get; set; }
}
//Areas has a name property I want to show on the second level under the group
public ObservableCollection<BuildTree> MyObsvCollection
{
get { return _myCollection; }
}
这是我的Xaml
<TreeView ItemsSource="{Binding MyObsvCollection}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate>
<TextBlock Foreground="Red" Text="{Binding Groups}" />
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Areas}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
答案 0 :(得分:1)
您的HierarchicalDataTemplate
没有要显示的项目。您应将ItemsSource
移至外HierarchicalDataTemplate
,然后ItemTemplate
可以简单DataTemplate
<HierarchicalDataTemplate ItemsSource="{Binding Areas}">
<TextBlock Foreground="Red" Text="{Binding Groups}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>