c# - 如何以编程方式刷新组合框的项目源的绑定(bind)?

标签 c# wpf binding combobox

我在 SO 上找到了一些关于这个问题的条目,但它们并不令我满意。他们谈论 INotifyProperyChanged,但这对我的情况没有帮助。

我有一个组合框。 对于 ItemsSource,我使用一个 MultiBinding 和一个 Converter 来创建一个 ICollectionViewICollectionView 绑定(bind)到 ItemsSource

GotFocus 事件中,需要刷新此绑定(bind),因此转换器会再次触发。

我该怎么做?

最佳答案

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

这是解决方案:

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();
        }
    }
}

关于c# - 如何以编程方式刷新组合框的项目源的绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1137538/

相关文章:

c# - Linq 查询返回具有特定属性值的嵌套数组

c# - 如何在 ASP.NET GridView 中的 BoundField 上方添加一行

wpf - 绑定(bind)路径中的括号是什么意思?

c# - 如何更改默认的 WCF 服务绑定(bind)?

.net - .net 中的绑定(bind)重定向问题

c# - .NET核心JWE : no "cty" header

c# - 线程化对象中包含的方法 - C#

c# - 如何使用 LINQ 在 ComboBox 中显示不同的属性值?

wpf - 如何使用 Live Visual Tree 检查工具提示?

c# - Wpf 图像控件(绑定(bind)到属性)第一次后不刷新