如何更新wpf中的组合框项? [英] How to update combo box item in wpf?

查看:65
本文介绍了如何更新wpf中的组合框项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在wpf应用程序中有组合框。在组合框选择更改事件我已在组合框中添加了一个项目。我已经将组合框与wvvm架构绑定在一起。
在selectionchanged上我的列表已更新,但组合框项目未刷新。我的xaml代码如下:

<ComboBox Name="cmb"  SelectionChanged="cmb_SelectionChanged"
             ItemsSource="{Binding Source={StaticResource cmbList}}" 
             SelectedValue="{Binding Listvalue}" DisplayMemberPath="ItemName" SelectedValuePath="itemName" >                    
            </ComboBox>

我使用了以下代码:sectionChanged:

 private void cmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        DropDownItem newItemsValue = new DropDownItem { ID = 1, itemName = "newValue", strID = "newValue" };
        this.objcmbList.cmbList.Add(newItemsValue);          
        (FindResource("CmbList") as ObjectDataProvider).ObjectInstance = this;
        (FindResource("CmbList") as ObjectDataProvider).Refresh();
    }




这里我的列表已更新,但组合框未更新。可能是Error是正在使用的组合框。那么如何在选择更改事件上刷新我的组合框项目。

推荐答案

以下几点:

1&NBSP;您有一个更改选择的事件和一个绑定的SelectedValue。 如果绑定值,则不需要该事件。

1.  You have both an event for selection changed and a bound SelectedValue.  You don't need the event if you bind the value.

2. 您将ItemsSource作为StaticResource。 这意味着它解决了一次。 使用DynamicResource。

2.  You have the ItemsSource as a StaticResource.  What that means is it resolves it once.  Use a DynamicResource.


这篇关于如何更新wpf中的组合框项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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