繁体   English   中英

如何以编程方式刷新组合框的itemssource的绑定?

[英]How to refresh a binding of the itemssource of a combobox programmatically?

我在SO上发现了一些关于这个问题的项目,但他们并不满足我。 他们谈论INotifyProperyChanged,但这对我的情况没有帮助。

我有一个Combobox 对于ItemsSource ,我使用MultiBindingConverter来创建ICollectionView ICollectionView绑定到ItemsSource

GotFocus -event上,需要刷新此绑定,以便再次触发转换器。

我怎样才能做到这一点?

好吧,一位同事帮助了我。

这是解决方案:

private void theComboBox_OnGotFocus(object sender, RoutedEventArgs e)
{
    ComboBox theComboBox = sender as ComboBox;

    if (theComboBox != null)
    {
        MultiBindingExpression binding = BindingOperations.GetMultiBindingExpression(theComboBox, ComboBox.ItemsSourceProperty);
        if (binding != null)
        {
            binding.UpdateTarget();
        }
    }
}

如果您可以在后面的代码中访问ICollectionView,您可能想尝试刷新方法...

希望这可以帮助..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM