Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InsertRange Help :D #21

Closed
ghost opened this issue Jun 13, 2017 · 2 comments
Closed

InsertRange Help :D #21

ghost opened this issue Jun 13, 2017 · 2 comments
Labels

Comments

@ghost
Copy link

ghost commented Jun 13, 2017

Hi James!. I would like to have a method to insert a collection, would you mind to give me some guidance of how can i help you to build such feature? Thanks :D

@weitzhandler
Copy link

I can do it, but i'd first wanna see my PR merged, check it out #26.
Looks like @jamesmontemagno is busy, I hope he gets to do some maintenance around here a bit.

@taublast
Copy link

taublast commented Dec 4, 2017

You can subclass ObservableRangeCollection and just add a new method:

       //-------------------------------------------------------------
        public void InsertRange(int index, IEnumerable<T> collection)
        //-------------------------------------------------------------
        {
            CheckReentrancy();

            int currentIndex = index;
            var changedItems = collection is List<T> ? (List<T>)collection : new List<T>(collection);
            foreach (var i in changedItems)
            {
                Items.Insert(currentIndex, i);
                currentIndex++;
            }
            OnPropertyChanged(new PropertyChangedEventArgs("Count"));
            OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, changedItems, index));
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants