【发布时间】:2012-03-14 10:07:46
【问题描述】:
我上课了:
public class Comment
{
...
public List<Comment> Children;
}
在我的 ViewModel 中,我有一个带有评论的 ObservableCollection,绑定正在工作,但我还想绑定孩子。
这是我的观点:
<ListBox
ItemsSource="{Binding Comments}"
ItemTemplate="{Binding Source={StaticResource comment}}">
</ListBox>
模板是每个 Comment 内容和子项的 UserControl 绑定:
<Grid>
<TextBlock Text="{Binding Body}" />
<ListBox
ItemsSource="{Binding Children}"
ItemTemplate="{Binding Source={StaticResource comment}}">
</ListBox>
</Grid>
显然我无法绑定 Children,因为我需要一个 ObservableCollection,但我不知道该怎么做,如果我在 Comment 类中将 List 替换为 ObservableCollection,它也不起作用。
现在,我只在 ViewModel 的列表中列出我的评论,但我想为每个孩子递归地做。
谢谢
【问题讨论】:
标签: c# wpf list binding observablecollection