public void VerifyCallingResetMultipleTimesOnUniqueIdItemsSource() { RunOnUIThread.Execute(() => { var data = new CustomItemsSourceWithUniqueId(Enumerable.Range(0, 5).ToList()); var repeater = new ItemsRepeater() { ItemsSource = data, Animator = new DefaultElementAnimator() }; Content = new Windows.UI.Xaml.Controls.ScrollViewer() { Width = 400, Height = 400, Content = repeater }; Content.UpdateLayout(); data.Reset(); data.Reset(); Content.UpdateLayout(); Verify.AreEqual(5, repeater.ItemsSourceView.Count); for (int i = 0; i < 5; i++) { Verify.IsNotNull(repeater.TryGetElement(i)); } }); }
// [TestMethod] Issue 1018 public void ValidateFocusMoveOnElementClearedWithUniqueIds() { ItemsRepeater repeater = null; CustomItemsSource dataSource = null; RunOnUIThread.Execute(() => { dataSource = new CustomItemsSourceWithUniqueId(Enumerable.Range(0, 5).ToList()); }); repeater = SetupRepeater(dataSource, "<Button Content='{Binding}' Height='10' />"); // dataSource: 0 1 2 3 4 // Index 0 deleted, focus should be on the new element which has index 0 SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, 0); }, () => { dataSource.Remove(0 /* index */, 1 /* count */, true /* reset*/); }, () => { ValidateCurrentFocus(repeater, 0 /*expectedIndex */, "1" /* expectedContent */); } }); // dataSource: 1 2 3 4 // Last element deleted, focus should move to the previous element int lastIndex = dataSource.Inner.Count - 1; SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, lastIndex); }, () => { dataSource.Remove(lastIndex /* index */, 1 /* count */, true /* reset*/); }, () => { ValidateCurrentFocus(repeater, 2 /*expectedIndex */, "3" /* expectedContent */); } }); // dataSource: 1 2 3 // Reset should keep the focused element as long as the unique id matches. SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, 0); }, () => { dataSource.Reset(); }, () => { int newIndex = dataSource.Inner.IndexOf(1); ValidateCurrentFocus(repeater, newIndex /*expectedIndex */, "1" /* expectedContent */); } }); // dataSource: 1 2 3 // Remove multiple elements SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, 0); }, () => { dataSource.Remove(0 /* index */, 2 /* count */, true /* reset*/); }, () => { ValidateCurrentFocus(repeater, 0 /*expectedIndex */, "3" /* expectedContent */); } }); }
public void ValidateStableResets() { RunOnUIThread.Execute(() => { var dataSource = new CustomItemsSourceWithUniqueId(Enumerable.Range(0, 3).ToList()); var repeater = SetupRepeater(dataSource); Log.Comment("Reset collection"); dataSource.GetAtCallCount = 0; dataSource.Reset(); repeater.UpdateLayout(); // Make sure data was not requested because during a stable reset // the elements and associated bound data are reused Verify.AreEqual(0, dataSource.GetAtCallCount); var realized = VerifyRealizedRange(repeater, dataSource); Verify.AreEqual(3, realized); }); }
public void ValidateElementIndexChangedEventOnStableReset() { CustomItemsSource dataSource = null; RunOnUIThread.Execute(() => dataSource = new CustomItemsSourceWithUniqueId(Enumerable.Range(0, 10).ToList())); var repeater = SetupRepeater(dataSource); RunOnUIThread.Execute(() => { List <int> preparedIndices = new List <int>(); List <int> clearedIndices = new List <int>(); List <KeyValuePair <int, int> > changedIndices = new List <KeyValuePair <int, int> >(); repeater.ElementPrepared += (sender, args) => { preparedIndices.Add(args.Index); }; repeater.ElementClearing += (sender, args) => { clearedIndices.Add(sender.GetElementIndex(args.Element)); }; repeater.ElementIndexChanged += (sender, args) => { changedIndices.Add(new KeyValuePair <int, int>(args.OldIndex, args.NewIndex)); }; Log.Comment("(UniqueId Reset) Insert in realized range: Inserting 1 item at index 1"); dataSource.Insert(index: 1, count: 1, reset: true, valueStart: 2000); repeater.UpdateLayout(); Verify.AreEqual(1, preparedIndices.Count); Verify.AreEqual(1, preparedIndices[0]); Verify.AreEqual(1, changedIndices.Count); Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(1, 2))); foreach (var ch in changedIndices) { Log.Comment("Changed " + ch.Key + " " + ch.Value); } Verify.AreEqual(1, clearedIndices.Count); Verify.AreEqual(2, clearedIndices[0]); preparedIndices.Clear(); clearedIndices.Clear(); changedIndices.Clear(); Log.Comment("(UniqueId Reset) Remove in realized range: Removing 1 item at index 0"); dataSource.Remove(index: 0, count: 1, reset: true); repeater.UpdateLayout(); Verify.AreEqual(1, clearedIndices.Count); Verify.AreEqual(0, clearedIndices[0]); foreach (var ch in changedIndices) { Log.Comment("Changed " + ch.Key + " " + ch.Value); } Verify.AreEqual(1, preparedIndices.Count); Verify.AreEqual(2, preparedIndices[0]); Verify.AreEqual(2, changedIndices.Count); Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(1, 0))); Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(2, 1))); }); }