本文介绍了如何强制刷新 WPF 绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用简单绑定附加项目源的组合框.加载组合框后,有没有办法刷新此绑定?
I have got a combo box with items source attached using simple binding. Is there any way to refresh this binding once combo box is loaded?
推荐答案
您可以使用绑定表达式:
You can use binding expressions:
private void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
((ComboBox)sender).GetBindingExpression(ComboBox.ItemsSourceProperty)
.UpdateTarget();
}
但是正如 Blindmeis 指出的,您还可以触发更改通知,如果您的集合实现了 INotifyCollectionChanged
(例如在 ObservableCollection
中实现)它会同步,所以你不需要做任何这些.
But as Blindmeis noted you can also fire change notifications, further if your collection implements INotifyCollectionChanged
(for example implemented in the ObservableCollection<T>
) it will synchronize so you do not need to do any of this.
这篇关于如何强制刷新 WPF 绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!