Users Pricing

forum

Home Forums WPF: Binding List to ListBox in wpf? – MindStick

WPF: Binding List to ListBox in wpf?

Dag Hammarskjold 4264 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

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md