【发布时间】:2012-05-24 00:51:51
【问题描述】:
我有一个简化为以下 XAML 的 ListBox
<ListBox ItemsSource="{Binding Properties}"
DisplayMemberPath="Name"
SelectedItem="SelectedProperty" />
在我的 ViewModel 中:
private List<Property> propertyList;
private Property selectedProperty;
public List<Property> Properties
{
get
{
return propertyList;
}
set
{
propertyList = value;
NotifyPropertyChanged("Properties");
}
}
public Property SelectedProperty
{
get
{
return selectedProperty;
}
set
{
NotifyPropertyChanged("SelectedProperty");
selectedProperty= value;
}
}
我的列表框填充得很好,但无论我尝试什么,当我在列表框中选择一个项目时,似乎都无法更新 SelectedProperty。我尝试将其全部切换为使用 ObservableCollection 而不是 List 并为 CollectionChanged 添加事件处理程序,但这没有奏效。
我确定我错过了一些愚蠢的东西,我只见树木不见森林。我已经走到了尽头,需要有人介入并提供帮助。
【问题讨论】:
标签: c# wpf data-binding mvvm listbox