Questions tagged [observablecollection]

ObservableCollection is a .NET collection class that sends event notifications when items are added, removed, replaced, moved, or reordered in the collection, or when the entire contents of the collection are replaced.

ObservableCollection is an implementation of the Observer Pattern specifically to notify when the contents of a collection of items changes. It implements the INotifyCollectionChanged interface which defines a CollectionChanged event property.

Listeners can subscribe to the CollectionChanged event to be notified when items are added, deleted, replaced, moved, or reordered within the collection or when the entire contents of the collection is replaced.

ObservableCollection also implements INotifyPropertyChanged and its PropertyChanged event, but this event only fires when properties of the collection object change, not when properties of the items in the collection change. If you want to be notified when any property of any item in the collection is changed, you have to hook the PropertyChanged event of every item as it is inserted into the collection. This can be done in a CollectionChanged event handler.

Notes on XAML Usage

ObservableCollection<T> can be used as a XAML object element in Windows Presentation Foundation (WPF), in versions 3.0 and 3.5. However, the usage has substantial limitations.

ObservableCollection<T> must be the root element, because the x:TypeArguments attribute that must be used to specify the constrained type of the genericObservableCollection<T> is only supported on the object element for the root element.

You must declare an x:Class attribute (which entails that the build action for this XAML file must be Page or some other build action that compiles the XAML). ObservableCollection<T> is in a namespace and assembly that are not initially mapped to the default XML namespace. You must map a prefix for the namespace and assembly, and then use that prefix on the object element tag for ObservableCollection<T>.

A more straightforward way to use ObservableCollection<T> capabilities from XAML in an application is to declare your own non-generic custom collection class that derives from ObservableCollection<T>, and constrains it to a specific type. Then map the assembly that contains this class, and reference it as an object element in your XAML.

2867 questions
0
votes
0 answers

Best async await pattern for Read and Relolad data scenario

I have not yet found a definitive solution for those scenarios. I need to load data and it's foreign data asyncronously from db. Data is the ItemSource of a DataGrid ForeignData is the ItemSource of Combos in some DataGridColumns There are two…
Noschema
  • 31
  • 6
0
votes
2 answers

C#/WPF - View does not update, no known fix works

Greetings StackOverflow! I'm trying to create a simple launcher that asks a set of questions. Six pages/views(that i'm yet to implement) - one question each. The idea is that user is able to switch between pages using two big side-buttons or to pick…
Thops
  • 15
  • 4
0
votes
1 answer

How to update blazor view observable collection mvvm .net maui

I've got a collection that takes a little while to populate so I want to show the other data on the screen first and then load in that collection incrementally (I do this with ajax and partials on the web but that doesn't work in a .net maui…
Jimmy
  • 2,191
  • 6
  • 25
  • 45
0
votes
2 answers

How to update ObservableCollection in UI?

foreach (var t in ((App)App.Current).CollectionMessages) if (t.Uid.ToString() == uid) t.TexT = z; The item in CollectionMessages, filed TexT changes Text to what I want. But the UI has no changes, it shows old value. What's wrong?Please help…
SevenDays
  • 3,718
  • 10
  • 44
  • 71
0
votes
0 answers

.Net Maui Binding ViewModel to SQLite database to populate CollectionView

I'm following Gerald Versluis's videos https://www.youtube.com/watch?v=uxqQqyuZ3Qo https://www.youtube.com/watch?v=8_cqUvriwM8 All good (and great teaching), but uses code behind and I'm trying to be a good boy and learn mvvm and binding - and…
gfmoore
  • 976
  • 18
  • 31
0
votes
1 answer

Xamarin - Update Observable Collection Not Working

I have a Xamarin project in which I have a Cart Page. I'm trying to update the data whenever I click on an add or remove button but it doesn't. Here's the code public class CartViewModel : BindableObject { .... private…
robluc
  • 121
  • 12
0
votes
0 answers

ObservableCollaction.Remove() method in the XamarinForms.iOS project

The mentioned code is a part of the custom control that we have written. While removing the items from the collection view we are getting the System.ArgumentOutofRange Exception with message Index was out of range, Must be a non-negative and less…
0
votes
1 answer

ObservableCollection in ViewModel doesn't render after filtering in - Maui/WinUI

I'm playing around with a MAUI application, and have an ObservableCollection bound to a FlexLayout in Xaml ContentPage. The collection displays fine initially, but I've added some filtering logic, and after filtering the collection fails to render.…
Justiciar
  • 356
  • 1
  • 3
  • 20
0
votes
3 answers

Add/Delete Item in real-time from ListView (C# MVVM WPF)

I have a ListView with an ObservableCollection. The class User has a List with Groups. I have another ListView which shows the Groups of the selected User. Now i try to add/delete groups, but they don't refresh in realtime. If i select another user…
DerKiLLa
  • 135
  • 12
0
votes
2 answers

ObservableCollection is not updating inside of a Parallel.Foreach

I have an ObservableCollection called AllVideos. I am using INotifyPropertyChanged on the video model as well as the AllVideos collection. For each file in a File Picker, I am running a method called ProcessMetaData() in a Parallel.ForEach. …
0
votes
0 answers

Connecting an ObservableCollection to Listview for a Windows Application UI (Visual Studio C#)

I'm working on a project where an application displays data by pulling it from a file and displaying a new data value every second. (edit: consolidated code at the end). While displaying changing data in textblocks work fine, what I'm trying to do…
0
votes
0 answers

CollectionChanged in ObservableCollection is null

I have an ObservableCollection of objects of a certain class. When I assign it a new value my CollectionChanged is null and UI don't update. If I in constructor set beginning items to Collection like this: public TabPageViewModel() { …
Jorr1
  • 11
  • 6
0
votes
1 answer

MVVM ListBox won't update with filtered Collection

in XAML: in CodeBehind: DataContext = new LoadJobWindowViewModel(); //ctor where…
stk1541
  • 71
  • 2
  • 10
0
votes
1 answer

ObserableCollection not triggering Change when Items are added/removed from list

I have a problem with ReactiveUI ObservableCollection. I am trying to update the UI based on a list that changes in a ReactiveObject, but for some reason my list change is not triggered and I am not sure what I am doing wrong. There is a full repo…
CiucaS
  • 2,010
  • 5
  • 36
  • 63
0
votes
1 answer

Collection Document Id in firebase

How I get the generated document ID of a collection in Firestore?
1 2 3
99
100