1
我有一个wpf组合框。它的ItemsSource绑定到ObservebaleCollection。显示的值(通过DisplayMemberPath)是Entity类的Name属性。 问题是当我更新当前选择的实体名称并且触发NotifyPropertyChnage时,它不会在UI中更新(甚至当我打开组合列表时它将在那里更新)。 我想问题是,实体哈希码仍然是相同的,组合没有看到差异。我能做什么?更新显示字段在组合框DisplayMemberPath未显示
XAML:
<ComboBox ItemsSource="{Binding Entities, Mode=OneWay}"
SelectedItem="{Binding CurrentEntity}"
DisplayMemberPath="Name"/>
代码:
public event PropertyChangedEventHandler PropertyChanged;
ObservableCollection<Entity> m_entities = new ObservableCollection<Entity>();
public ObservableCollection<Entity> Entities{get{return m_entities;}}
public Entity CurrentEntity{get;set}
public void RenameEntity(string name)
{
m_currentEntity.Name = name;
PropertyChanged(this, new PropertyChangedEventArgs("CurrentEntity"));
PropertyChanged(this, new PropertyChangedEventArgs("Entities"));
}
首先,你可以张贴一些代码:) – 2011-02-01 09:01:16
我我有同样的问题。我通过在项目名称后面的代码中清除并重新分配DisplayMemberPath(DisplayMemberPath指向的内容)被更改,从而强制刷新它。我知道这是愚蠢的解决方案,但这是我认为的最简单的解决方案。 – 2015-02-13 17:57:51