1 回答
TA贡献1804条经验 获得超7个赞
经过多次故障排除,我能够找出答案。onItemsSourceChanged 在实例化控件后未触发,因此在应用程序初始启动后从未进行过更新。我将多功能组合盒上的OnItemsSourceChanged函数编辑到下面,以便它可以在更改的事件上触发,并且它现在按预期工作。
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MultiSelectComboBox control = (MultiSelectComboBox)d;
var action = new NotifyCollectionChangedEventHandler(
(o, args) =>
{
MultiSelectComboBox c = (MultiSelectComboBox)d;
c?.DisplayInControl();
});
if (e.OldValue != null)
{
var sourceCollection = (ObservableDictionary<string, object>)e.OldValue;
sourceCollection.CollectionChanged -= action;
}
if (e.NewValue != null)
{
var sourceCollection = (ObservableDictionary<string, object>)e.NewValue;
sourceCollection.CollectionChanged += action;
}
control.DisplayInControl();
}
- 1 回答
- 0 关注
- 158 浏览
添加回答
举报