如何强制WPF绑定刷新? [英] How to force a WPF binding to refresh?

查看:823
本文介绍了如何强制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?

推荐答案

您可以使用绑定前pressions:

You can use binding expressions:

private void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
    ((ComboBox)sender).GetBindingExpression(ComboBox.ItemsSourceProperty)
                      .UpdateTarget();
}

作为Blindmeis指出还可以火更改通知,进一步,如果你的集合实现 INotifyCollectionChanged (例如,在实施的ObservableCollection< T> )。它会同步,这样你就不需要做任何的这种

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绑定刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆