0
votes

I have a Public Property StaticFailingPinListItem As New ObservableCollection(Of MyClass) in my main user control, UserControl1.

Public Class UserControl1
  Public Property StaticFailingPinListItem As New ObservableCollection(Of MyClass)  

MyClass has two properties - PinName & ImageLocation.

Public Class MyClass
  Implements INotifyPropertyChanged
  Public Property PinName
  Public Property ImageLocation

If I manually add items to the collection at runtime, I would be able to view PinName property in my listbox. However, it doesn't work if I were to add items at a later time (eg: after a button is clicked).

This is my xaml:

    ItemsSource="{Binding ElementName =data2, Path=StaticFailingPinListItem}" DisplayMemberPath="PinName"

So, the question is how I do a code-behind databinding for my listbox after the collection is populated?

1

1 Answers

0
votes

Interface INotifyPropertyChanged must be implemented by a class which contain a bonded property.
In your case this must be UserControl1

You need to implement this interface on the UserControl1 type

Public Class UserControl1
    Implements INotifyPropertyChanged
Public Property StaticFailingPinListItem As New ObservableCollection(Of MyClass) 

When you add items after button is clicked, then control will be notified about changes in collection