New to Telerik UI for WinUI? Download free 30-day trial

RadObservableCollection

This article describes RadObservableCollection.

RadObservableCollection is an observable collection (INotifyCollectionChanged implementation) which extends the BindableCollection class. The addition to this collection type is the ability to suspend collection change notification events.

Each collection change in an observable collection will notify the UI that something is updated. To prevent this and boost the overall performance in some situations, use the SuspendNotifications method of RadObservableCollection. The method call disables the code that raises the CollectionChanged event when the collection is updated.

To resume the collection change notifications, call the ResumeNotifications method of RadObservableCollection. The ResumeNotifications method call will raise the CollectionChanged event with NotifyCollectionChangedAction.Reset.

Example 1: Using RadObservableCollection suspension mechanism

myRadObservableCollection.SuspendNotifications(); 
foreach (var item in newItems) 
{ 
    myRadObservableCollection.Add(item); 
} 
myRadObservableCollection.ResumeNotifications(); 
RadObservableCollection provides several additional methods.
  • Reset: Raises the CollectionChanged event with NotifyCollectionChangedAction.Reset.

  • AddRange: Adds the elements of the specified collection to the end of the RadObservableCollection. You can use this method to perform a bulk add operation.

  • InsertRange: Inserts the elements of the specified collection at the specified index. You can use this method to perform a bulk add operation, starting at the specified index.

  • RemoveRange: Removes the elements of the specified collection from the RadObservableCollection. You can use this method to perform a bulk remove operation.

    The AddRange, InsertRage and RemoveRange methods call the ResumeNotifications method internally, even if notifications were previously suspended manually.

The collection provides few additional events.

  • CollectionChanging: Occurs when collection is changing - i.e., an item is being added/removed. The CollectionChangingEventArgs of the event handler holds the following properties:

    • Action: Gets or sets the collection change action. It is of type CollectionChangeAction.
    • Cancel: Set this to True to cancel the changes.
    • Index: Gets or sets the index of the current item being added/removed.
    • Item: Gets or sets the currently added/removed item.
  • PropertyChanged: Occurs when a property value changes. The PropertyChangedEventArgs provides access to the property name via the PropertyName field.

See Also

In this article
Not finding the help you need?