Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have an observable collection...
SelectableDataContext<T>
..And in the generic class
SelectableDataContext<T>
is...having two private member variables
Private T item.
Private bool isSelected.
When the IsSelected property changes...My collection's changed property is not firing .
I think it should fire...because it's
Reset
in
INotifyCollectionChangedAction
.
This is an old question but for the benefit of anyone who may come across this through a search as I did:
NotifyCollectionChangedAction.Reset
means "The content of the collection changed dramatically". One case where the Reset event is raised is when you call
Clear()
on the underlying observable collection.
With the Reset event, you don't get the
NewItems
and
OldItems
collections in the
NotifyCollectionChangedEventArgs
parameter.
This means you're better off using the "sender" of the event to get a reference to the modified collection and use that directly, i.e. assume it's a new list.
An example of this might be something like:
((INotifyCollectionChanged)stringCollection).CollectionChanged += new NotifyCollectionChangedEventHandler(StringCollection_CollectionChanged);
void StringCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
switch (e.Action)
case NotifyCollectionChangedAction.Add:
foreach (string s in e.NewItems)
InternalAdd(s);
break;
case NotifyCollectionChangedAction.Remove:
foreach (string s in e.OldItems)
InternalRemove(s);
break;
case NotifyCollectionChangedAction.Reset:
ReadOnlyObservableCollection<string> col = sender as ReadOnlyObservableCollection<string>;
InternalClearAll();
if (col != null)
foreach (string s in col)
InternalAdd(s);
break;
Lots of discussions on this Reset event here: When Clearing an ObservableCollection, There are No Items in e.OldItems.
–
–
–
There is a difference between INotifyCollectionChanged
and INotifyPropertyChanged
.
When a value of a propery in an object changes, it should notify others using INotifyPropertyChanged
interface implementation.
On the other hand, when number of items
or items themselves
change in a collection, it should let others know using INotifyCollectionChanged
implementation.
Now, in your case, value of a property of an object in your collection changes. That is supposed to raise PropertyChanged
event, not CollectionChanged
event.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.