Users Pricing

forum

home / developersection / forums / wpf: binding list to listbox in wpf?

WPF: Binding List to ListBox in wpf?

Dag Hammarskjold 4196 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?


1 Answers