Git Product home page Git Product logo

rangedobservablecollection's Introduction

RangedObservableCollection

Build status NuGet NuGet Pre Release

A small extension to ObservableCollection that allows for multiple items to be added, removed or replaced in a single operation.

RangedObservableCollection

A small extension to ObservableCollection that allows for multiple items to be added, removed or replaced in a single operation.

This library is simple and just adds a few extra methods:

var collection = new RangedObservableCollection<int>();

// bulk add
var itemsToAdd = new [] { 1, 2, 3, 4, 5 };
collection.AddRange(itemsToAdd);

// bulk remove
var itemsToRemove = new [] { 1, 2, 3, 4, 5 };
collection.RemoveRange(itemsToRemove);

// bulk clear and add
var itemsToReplace = new [] { 1, 2, 3, 4, 5 };
collection.ReplaceRange(itemsToReplace);

rangedobservablecollection's People

Contributors

mattleibow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rangedobservablecollection's Issues

Range actions are not supported Exception

I replaced my ObservableCollection with this one and I get

System.NotSupportedException: 'Range actions are not supported.'

on line

OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, changedItems, startIndex));

Using WPF and .NET 4.8. Am I missing something?

Edit: more info:

Stack Trace

at System.Windows.Data.ListCollectionView.ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.RangedObservableCollection1.AddRange(IEnumerable`1 collection) in D:...\RangedObservableCollection.cs:line

when I try

List<object> templist = new List<object>();
...
FilesCollection.AddRange(templist);

AddRange should avoid sending notifications if no items added

AddRange() should probably avoid sending the property changed notifications if the passed in collection is empty and no items are added. I ran into some downstream index out-of-range exceptions in a UWP app when AddRange() was called and no items were added to a collection that was already empty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.