Questions tagged [inotifycollectionchanged]

is a .NET interface for providing collection subscribers notification on changes, mostly used in WPF UI binding.

From MSDN: You can enumerate over any collection that implements the IEnumerable interface. However, to set up dynamic bindings so that insertions or deletions in the collection update the UI automatically, the collection must implement the INotifyCollectionChanged interface. This interface exposes the CollectionChanged event that must be raised whenever the underlying collection changes.

WPF provides the ObservableCollection class, which is a built-in implementation of a data collection that exposes the INotifyCollectionChanged interface. For an example, see How to: Create and Bind to an ObservableCollection.

The individual data objects within the collection must satisfy the requirements described in the Binding Sources Overview.

129 questions
1
vote
0 answers

Proper pattern for C# assignment, property of object is collection

I have a class that exposes different types of collections as properties, like List
and SortedSet. I understand collection classes should be read-only, that we should not expose a collection for update, like person.Address[3].City =…
1
vote
1 answer

DataGridView and INotifyCollectionChanged

I had it in my mind that if I implemented INotifyCollectionChanged on my Custom Collection that the DataGridView would subscribe to the CollectionChanged event. My Collection implements IListSource and INotifyCollectionChanged, and has an internal…
BVernon
  • 3,205
  • 5
  • 28
  • 64
1
vote
1 answer

Add CollectionChanged to ObservableColleciton without knowing collection type

I am trying to add a CollectionChanged event to any item within a class. Assume I have the following: public class A { string OneString; string TwoString; ObservableCollection CollectionOfB; } public class B { string ThreeString; …
1
vote
1 answer

Handling ObservableCollection CollectionChanged Event

I've seen code like the following in the Silverlight toolkit and can't understand how it is safe to do: private void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // Update the cache if (e.Action ==…
1
vote
1 answer

How to Bind Data to DataGrid at Run-Time

All, I have some test code that works with some test data defined as private ObservableCollection _testData = new ObservableCollection(); public ObservableCollection TestData { get { return _testData; } set…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
1
vote
1 answer

Why does DataGrid call collection's IndexOf passing the object of type ItemcControl.ItemInfo?

I created SelectionHelper for DataGrid which allows binding for selected items in both directions. In this helper I call ScrollIntoView for the first selected item, when selection changes from viewmodel. The call successfully returns. But later…
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
1
vote
2 answers

Implementing INotfyPropertyChanged for calculated properties

I'm a bit new to MVVM, and was wondering Let's say I have defined a ObservableCollection Diffs property. I also have the following property: public bool IsSame { get { return Diffs.Count == 0; } } I dont get how…
Tomer W
  • 3,395
  • 2
  • 29
  • 44
0
votes
3 answers

Why does INotifyCollectionChanged use IList

Reading up here, I undestand why it is not IList. But why IList at all? It makes no sense to add to it, so it should be just an IEnumerable, or if you really want an indexer (no reason why), use a ReadOnlyCollection.
TDaver
  • 7,164
  • 5
  • 47
  • 94
0
votes
1 answer

ObservableCollection binding to dataTemplate with async data

I am very new in WPF, those are very confuse to me. the main aim is I want a WPF program that fetches data every 5 seconds from WebAPI, and display the data. I am using this MS sample code to…
0
votes
0 answers

CollectionChanged - how to implement in a View

I am trying to implement the CollectionChanged or ListChanged event in my View. After a lot of research and experimenting I visualized the differencene between PropertyChanged and CollectionChanged on an ObservableCollection (code and output are…
karwenzman
  • 23
  • 1
  • 1
  • 8
0
votes
0 answers

Set event on object's parameter updated in observable collection

As for question, I have an ObservableCollection of objects, declared in a UserControl and binded to an ItemsControl.ItemsSource. Its properties are updated during the software run, eventually. I would like to catch the update event. I tried using…
0
votes
2 answers

using Reactive Extensions to monitor IEnumerable

I'm connecting to an object that asyncronously loads a collection of objects into an IEnumerable. At the time I connect, the IEnumerable may have items already in it's collection, and may add items during the lifetime of the application that I need…
Random
  • 1,896
  • 3
  • 21
  • 33
0
votes
1 answer

WPF, Update ComboBox ItemsSource when it's DataContext changes

I have two classes A and B which both implement an interface IThingWithList. public interface IThingWithList { ObservableCollection TheList; } TheList in A contains 1, 2, 3 TheList in B contains 4, 5, 6 I have a controller class which has a…
0
votes
1 answer

Is there a way to just require an object implement the members of an interface without requiring it to explicitly implement it in c#?

I am making a custom control similar to an ItemsControl so it has an Items property I want to be bindable to but in order for my control to update, the property must implement INotifyCollectionChanged. I'd like the user to be able to bind any object…
0
votes
2 answers

Errors Changed inside Collection Changed event does not get raised

I have an fullproperty like that in my VM: public ObservableCollection ServiceHosts { get => serviceHosts; set { if (serviceHosts == value) { return; } serviceHosts = value; OnPropertyChanged(); …
Stan1k
  • 338
  • 2
  • 17
1 2 3
8 9