Skip to content

Commit

Permalink
Merge pull request #1486 from Prin53/develop
Browse files Browse the repository at this point in the history
Fixes  #1485 - MvxObservableCollection RemoveRange raises Reset action
  • Loading branch information
martijn00 committed Nov 25, 2016
2 parents 9f64ff9 + f739d9d commit 813ee7e
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions MvvmCross/Core/Core/ViewModels/MvxObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void SwitchTo(IEnumerable<T> items)
/// </summary>
/// <param name="items">The collection which items will be removed.</param>
/// <exception cref="ArgumentNullException">The items list is null.</exception>
public void RemoveRange(IEnumerable<T> items)
public void RemoveItems(IEnumerable<T> items)
{
if (items == null)
{
Expand All @@ -213,7 +213,44 @@ public void RemoveRange(IEnumerable<T> items)
{
SuppressEvents = false;

OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove));
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}

/// <summary>
/// Removes the current <see cref="MvxObservableCollection{T}"/> instance items of the ones specified in the range, raising the minimum required change events.
/// </summary>
/// <param name="start">The start index.</param>
/// <param name="count">The count of items to remove.</param>
/// <exception cref="ArgumentOutOfRangeException">Start index or count incorrect</exception>
public void RemoveRange(int start, int count)
{
if (start < 0)
{
throw new ArgumentOutOfRangeException(nameof(start));
}

var end = start + count - 1;

if (end > Count)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

try
{
SuppressEvents = true;

for (var i = end; i >= start; i--)
{
RemoveAt(i);
}
}
finally
{
SuppressEvents = false;

OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}

Expand Down

0 comments on commit 813ee7e

Please sign in to comment.