Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can an ObservableCollection fire a Replace action?

In the documentation of the event args of NotifyCollectionChangedEventArgs, there is an action called Replace (in addition to Add, Remove, Move, etc.). When can this be fired? I can't see any Replace method in ObservableCollection

like image 370
Louis Rhys Avatar asked Jul 01 '11 02:07

Louis Rhys


People also ask

How does ObservableCollection work?

An ObservableCollection is a dynamic collection of objects of a given type. Objects can be added, removed or be updated with an automatic notification of actions. When an object is added to or removed from an observable collection, the UI is automatically updated.

What is the use of ObservableCollection in WPF?

WPF and Silverlight have a special generic collection class ObservableCollection which provides notification about updating such as when items get added, removed, or when the entire list is refreshed.


1 Answers

Here is an example:

ObservableCollection<string> myCollection = new ObservableCollection<string>;
myCollection.Add("One");
myCollection.Add("Two");
myCollection.Add("Three");
myCollection.Add("Four");
myCollection.Add("Five");

myCollection[4] = "Six"; // Replace (i.e. Set)
like image 77
CodeNaked Avatar answered Sep 30 '22 21:09

CodeNaked