我有一个简化后的ListBox XAML如下:
我的列表框可以正常填充,但是无论我尝试什么,似乎都不能在选择列表框中的项目时更新SelectedProperty。我已经尝试将其全部切换到使用ObservableCollection而不是List,并添加了CollectionChanged事件处理程序,但这并没有起作用。
我确信我错过了一些愚蠢的东西,看不见眼前的事物。我快要崩溃了,需要有人介入并提供帮助。
<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事件处理程序,但这并没有起作用。
我确信我错过了一些愚蠢的东西,看不见眼前的事物。我快要崩溃了,需要有人介入并提供帮助。