Ejemplo n.º 1
0
        // [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 */); }
            });
        }