0

I have a ListBox in WPF that I am trying to bind a class to that is a list with 2 properties which are FirstName and LastName. I bind the ItemSource and DisplayMemberPath in XAML and all works fine.

I now need to do this in code but all I see is the list with the class name so the DisplayMemberPath is not being bound correctly.

Dim b1 As New Binding
b1.Source = dc.People

Dim b2 As New Binding
b2.Path = New PropertyPath("FirstName")

BindingOperations.SetBinding(myListBox, ListBox.ItemsSourceProperty, b1)
BindingOperations.SetBinding(myListBox, ListBox.DisplayMemberPathProperty, b2)
4

1 回答 1

1

It is set as a property of the ListBox, not a binding.

myListBox.DisplayMemberPath = "FirstName" 
于 2018-09-16T14:40:16.900 回答