我有一個可編輯的組合框,我將對象列表中的名稱屬性綁定到(QBD.Name)。我無法弄清的是如何允許編輯這些名稱 - 當我嘗試編輯時,我不斷收到對象引用錯誤。可編輯的組合框綁定
我相信我需要實現INotifyPropertyChanged,但我不完全確定它是如何工作的。
這裏的綁定代碼:
<ComboBox Name="cmbBxQBDNames" Text="Please Select a QBD" ItemsSource="{Binding Path=QBDs, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" DisplayMemberPath="QBD.Name" SelectedValuePath="QBD.Name" IsEditable="True" VerticalAlignment="Center" HorizontalAlignment="Stretch" Width="auto" MinWidth="25" Margin="45,0,0,0" Foreground="Black"></ComboBox>
這裏是我綁定的對象:
Public Class QBDs
Private QBDsLocal As New ObservableCollection(Of QBD)
Public Property QBDs As ObservableCollection(Of QBD)
Get
Return QBDsLocal
End Get
Set(value As ObservableCollection(Of QBD))
QBDsLocal = value
End Set
End Property
End Class
Public Class QBD
Private NameLocal As String
Public Property Name As String
Get
Return NameLocal
End Get
Set(value As String)
NameLocal = value
End Set
End Property
End Class
而且,當我從下拉框中選擇一個對象,我怎麼能有它的名字顯示在組合框?目前,它仍然是空白的。
謝謝,但它並沒有做任何事情。 – user