Note that there are some explanatory texts on larger screens.

plurals
  1. POINotifyCollectionChanged is not updating the UI
    text
    copied!<p>I have a class as shown below. All the functions I have removed for brevity</p> <pre><code>public class PersonCollection:IList&lt;Person&gt; {} </code></pre> <p>Now I have one more Model class as shown below. AddValueCommand is class deriving from ICommand which again I am omiting.</p> <pre><code>public class DataContextClass:INotifyCollectionChanged { private PersonCollection personCollection = PersonCollection.GetInstance(); public IList&lt;Person&gt; ListOfPerson { get { return personCollection; } } public void AddPerson(Person person) { personCollection.Add(person); OnCollectionChanged(NotifyCollectionChangedAction.Reset); } public event NotifyCollectionChangedEventHandler CollectionChanged = delegate { }; public void OnCollectionChanged(NotifyCollectionChangedAction action) { if (CollectionChanged != null) { CollectionChanged(this, new NotifyCollectionChangedEventArgs(action)); } } ICommand addValueCommand; public ICommand AddValueCommand { get { if (addValueCommand == null) { addValueCommand = new AddValueCommand(p =&gt; this.AddPerson(new Person { Name = "Ashish"})); } return addValueCommand; } } } </code></pre> <p>In the main window I am binding my UI to Model as shown below </p> <pre><code> DataContextClass contextclass = new DataContextClass(); this.DataContext = new DataContextClass(); </code></pre> <p>And My UI looks like as shown below </p> <pre><code>&lt;ListBox Margin="5,39,308,113" ItemsSource="{Binding Path=ListOfPerson}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBox Height="20" Text="{Binding Path=Name}"&gt;&lt;/TextBox&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;Button Content="Button" HorizontalAlignment="Left" Command="{Binding Path=AddValueCommand}" Margin="233,39,0,73" /&gt; </code></pre> <p>My List Box is not updating with the new value when button is clicked. What I am missing here.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload