forum

Home / DeveloperSection / Forums / WPF: Binding List to ListBox in wpf?

WPF: Binding List to ListBox in wpf?

Dag Hammarskjold 3835 10-Aug-2013

I have a class:

public class A : INotifyPropertyChanged

{

    public List<B> bList { get; set; }

    public void AddB(B b)

    {

        bList.Add(b);

        NotifyPropertyChanged("bList");

    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(string info)

    {

        if (PropertyChanged != null)

        {

            PropertyChanged(this, new PropertyChangedEventArgs(info));

        }

    }

}

And a binding (DataContext of UserControl is an instance of A):

<ListBox ItemsSource="{Binding Path=bList}" />

Elements are shown, the ListBox is not updated after new object is added to List

After changing list to ObservableCollection and removing the NotifyPropertyChanged handler everything works.

Why the list is not working?


wpf wpf 
Updated on 10-Aug-2013

Can you answer this question?


Answer

1 Answers

Liked By