【发布时间】:2012-06-08 16:29:26
【问题描述】:
我正在使用 WPF,并且我正在使用 ListView,并且我需要在向其中添加项目时触发一个事件。我试过这个:
var dependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(ListView));
if (dependencyPropertyDescriptor != null)
{
dependencyPropertyDescriptor.AddValueChanged(this, ItemsSourcePropertyChangedCallback);
}
.....
private void ItemsSourcePropertyChangedCallback(object sender, EventArgs e)
{
RaiseItemsSourcePropertyChangedEvent();
}
但它似乎只有在整个集合被更改时才有效,我已经阅读了这篇文章:event-fired-when-item-is-added-to-listview,但最佳答案仅适用于 listBox。我试图将代码更改为 ListView 但我无法做到。
我希望你能帮助我。提前谢谢你。
【问题讨论】:
-
在您发布的问题的答案中,您会发现“修改了我上面的代码以使其更清晰。这也适用于任何 ItemsControl(ListBox 或 ListView)。” - 你有什么特别的问题?
-
@Slugart 感谢您的回复,我遇到的问题是
BeginInvoke方法不接受声明作为示例。它说DispatcherPriority不存在