public void DataGridGroupItem_IGridProvider() { PagedCollectionView customers = CreateGroupedCustomerCollectionView(); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 350; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; dataGrid.ItemsSource = customers; TestPeer testPeer = new TestPeer(dataGrid); Assert.IsNotNull(testPeer); TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); IGridProvider gridProvider = null; IRawElementProviderSimple item = null; EnqueueCallback(delegate { CollectionViewGroup group = customers.Groups[1] as CollectionViewGroup; Assert.IsNotNull(group, "PagedCollectionView did not return CollectionViewGroup"); AutomationPeer peer = new DataGridGroupItemAutomationPeer(group, dataGrid); Assert.IsNotNull(peer); gridProvider = peer.GetPattern(PatternInterface.Grid) as IGridProvider; Assert.IsNotNull(gridProvider); Assert.AreEqual(7, gridProvider.RowCount, "Incorrect RowCount value"); Assert.AreEqual(dataGrid.Columns.Count, gridProvider.ColumnCount, "Incorrect ColumnCount value"); item = gridProvider.GetItem(5, 2); Assert.IsNotNull(item, "GetItem returned null for valid cell"); AutomationPeer itemPeer = testPeer.GetPeerFromProvider(item); Assert.AreEqual(typeof(DataGridCell).Name, itemPeer.GetClassName(), "GetItem did not return DataGridCell"); item = gridProvider.GetItem(100, 100); Assert.IsNull(item, "GetItem returned object for invalid cell"); }); this.EnqueueYieldThread(); this.EnqueueCallback(delegate { // Collapse the group and check that GetItem still works dataGrid.CollapseRowGroup(customers.Groups[1] as CollectionViewGroup, true); }); this.EnqueueYieldThread(); this.EnqueueCallback(delegate { Assert.IsNotNull(gridProvider); item = gridProvider.GetItem(5, 2); Assert.IsNotNull(item, "GetItem returned null for valid cell"); AutomationPeer itemPeer = testPeer.GetPeerFromProvider(item); Assert.AreEqual(typeof(DataGridCell).Name, itemPeer.GetClassName(), "GetItem did not return DataGridCell"); }); EnqueueTestComplete(); }