using NUnit.Framework;
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
+using System.ComponentModel;
using System.Linq;
namespace Xamarin.Forms.Core.UnitTests
}
[Test]
+ public void TracksRemoveAll()
+ {
+ var layout = new StackLayout
+ {
+ IsPlatformEnabled = true,
+ };
+
+ var itemsSource = new ObservableRangeCollection<int>(Enumerable.Range(0, 10));
+ BindableLayout.SetItemsSource(layout, itemsSource);
+
+ itemsSource.RemoveAll();
+ Assert.IsTrue(IsLayoutWithItemsSource(itemsSource, layout));
+ }
+
+ [Test]
public void TracksReplace()
{
var layout = new StackLayout
}
}
+ class ObservableRangeCollection<T> : ObservableCollection<T>
+ {
+ public ObservableRangeCollection(IEnumerable<T> collection)
+ : base(collection)
+ {
+ }
+
+ public void RemoveAll()
+ {
+ CheckReentrancy();
+
+ var changedItems = new List<T>(Items);
+ foreach (var i in changedItems)
+ Items.Remove(i);
+
+ OnPropertyChanged(new PropertyChangedEventArgs("Count"));
+ OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
+ OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, changedItems, 0));
+ }
+ }
+
class MyDataTemplateSelectorTest : DataTemplateSelector
{
readonly Func<object, BindableObject, DataTemplate> _func;
{
if (e.OldStartingIndex == -1)
goto case NotifyCollectionChangedAction.Reset;
- for (int i = 0; i < e.OldItems.Count; ++i)
+ for (int i = 0; i < e.OldItems.Count; i++)
{
- layout.Children.RemoveAt(i + e.OldStartingIndex);
+ layout.Children.RemoveAt(e.OldStartingIndex);
}
}
break;