public void SetItemsSourceAndChangePageSize() { // Create the ItemsSource List <string> strings = new List <string>() { "one", "two", "three", "four" }; PagedCollectionView pagedCollectionView = new PagedCollectionView(strings); pagedCollectionView.MoveCurrentToLast(); // Create the DataGrid bool isLoaded = false; DataGrid dataGrid = new DataGrid(); dataGrid.Loaded += delegate { isLoaded = true; }; dataGrid.ItemsSource = pagedCollectionView; TestPanel.Children.Add(dataGrid); this.EnqueueConditional(delegate { return(isLoaded); }); // Initially, the DG's selected item should be the last item Assert.AreEqual(4, dataGrid.SlotCount, "Incorrect SlotCount after adding and removing items"); Assert.AreEqual(4, dataGrid.VisibleSlotCount, "Incorrect VisibleSlotCount after adding and removing items"); Assert.AreEqual(3, dataGrid.SelectedIndex, "SelectedIndex was not updated when collection changed"); Assert.AreEqual("four", dataGrid.SelectedItem, "SelectedItem was not updated when collection changed"); // Changing the PageSize should cause the current and selected item to change pagedCollectionView.PageSize = 2; this.EnqueueYieldThread(); this.EnqueueCallback(delegate { Assert.AreEqual(2, dataGrid.SlotCount, "Incorrect SlotCount after adding and removing items"); Assert.AreEqual(2, dataGrid.VisibleSlotCount, "Incorrect VisibleSlotCount after adding and removing items"); Assert.AreEqual(0, dataGrid.SelectedIndex, "SelectedIndex was not updated when collection changed"); Assert.AreEqual("one", dataGrid.SelectedItem, "SelectedItem was not updated when collection changed"); }); this.EnqueueTestComplete(); }