【发布时间】:2010-01-26 08:47:44
【问题描述】:
抱歉 - 我的问题与 this one 几乎相同,但由于没有得到可行的答案,我希望其他人有一些新的想法。
我有一个绑定到单一类型层次结构的 WPF TreeView:
public class Entity
{
public string Title { get; set; }
public ObservableCollection<Entity> Children { get; set; }
}
Entity 类实现了 INotifyPropertyChanged,但为了清楚起见,我省略了这段代码。
TreeView 绑定到 ObservableCollection
<TreeView ItemsSource="{Binding Path=Entities}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:Entity}" ItemsSource="{Binding Path=Children}">
<TextBlock Text="{Binding Path=Title}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
最初,TreeView 会按预期绑定并正确显示多级层次结构。此外,当以编程方式修改某个 Children 集合的成员资格时,更改会正确反映在 TreeView 中。
但是,对根成员级别 ObservableCollection
任何建议将不胜感激。
谢谢, 蒂姆
【问题讨论】:
标签: wpf binding treeview observablecollection root-node