Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing INotifyCollectionChanged interface
    primarykey
    data
    text
    <p>I need to implement a collection with special capabilities. In addition, I want to bind this collection to a ListView, Therefore I ended up with the next code (I omitted some methods to make it shorter here in the forum):</p> <pre><code>public class myCollection&lt;T&gt; : INotifyCollectionChanged { private Collection&lt;T&gt; collection = new Collection&lt;T&gt;(); public event NotifyCollectionChangedEventHandler CollectionChanged; public void Add(T item) { collection.Insert(collection.Count, item); OnCollectionChange(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); } protected virtual void OnCollectionChange(NotifyCollectionChangedEventArgs e) { if (CollectionChanged != null) CollectionChanged(this, e); } } </code></pre> <p>I wanted to test it with a simple data class:</p> <pre><code>public class Person { public string GivenName { get; set; } public string SurName { get; set; } } </code></pre> <p>So I created an instance of myCollection class as follows:</p> <pre><code>myCollection&lt;Person&gt; _PersonCollection = new myCollection&lt;Person&gt;(); public myCollection&lt;Person&gt; PersonCollection { get { return _PersonCollection; } } </code></pre> <p>The problem is that the ListView does not update when the collection updates although I implemented the INotifyCollectionChanged interface.</p> <p>I know that my binding is fine (in XAML) because when I use the ObservableCollecion class instead of myCollecion class like this:</p> <pre><code> ObservableCollection&lt;Person&gt; _PersonCollection = new ObservableCollection&lt;Person&gt;(); public ObservableCollection&lt;Person&gt; PersonCollection { get { return _PersonCollection; } } </code></pre> <p>the ListView updates</p> <p>What is the problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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