【发布时间】:2009-05-10 16:47:16
【问题描述】:
我有这个DependencyProperty,它拥有一个具有集合属性的实体 (ShoutBox.Entities):
public static readonly DependencyProperty ShoutBoxProperty = DependencyProperty.Register("ShoutBox",typeof (ShoutBox),typeof (ShoutBoxViewerControl));
public ShoutBox ShoutBox
{
get { return (ShoutBox) GetValue(ShoutBoxProperty); }
set { SetValue(ShoutBoxProperty, value); }
}
它被绑定在xaml 中,如下所示:
<ItemsControl ItemsSource="{Binding ShoutBox.Entries}">
.
.
</ItemsControl>
当我第一次绑定它时,它按预期工作,但有时我需要将项目添加到集合中(使用同一控件中的方法),如下所示:
public void AddNewEntry(ShoutBoxEntry newEntry)
{
Dispatcher.Invoke(new Action(() =>{
ShoutBox.Entries.Add(newEntry); //Adding directly the the Dependency property
}));
}
问题是当我使用上述方法添加一个新元素时,该项目没有显示在ItemsControl中。
我的问题是,为什么我添加的新元素没有显示在 ItemsControl 中?
[编辑]
Entries (ShoutBox.Entries) 的类型为 List<ShoutBoxEntry>
【问题讨论】:
标签: c# wpf data-binding xaml dependency-properties