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

Fixes #1485 - MvxObservableCollection RemoveRange raises Reset action #1486

Merged
merged 2 commits into from
Nov 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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