[英]WPF Listbox binding: SelectedItem not setting
我將ListBox簡化為以下XAML
<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添加事件處理程序,但這沒有用。
我確信我錯過了一些愚蠢的東西,並且看不到樹木的木頭。 我到達了我的系繩的末端,需要有人介入並提供幫助。
您需要綁定到SelectedProperty
:
<ListBox ItemsSource="{Binding Properties}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedProperty}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.