IRawElementProviderSimple[] ISelectionProvider.GetSelection() { DataGrid dataGrid = this.OwningDataGrid; int rowIndex = dataGrid.Items.IndexOf(_item); // If row has selection if (rowIndex > -1 && dataGrid.SelectedCellsInternal.Intersects(rowIndex)) { List <IRawElementProviderSimple> selectedProviders = new List <IRawElementProviderSimple>(); for (int i = 0; i < this.OwningDataGrid.Columns.Count; i++) { // cell is selected if (dataGrid.SelectedCellsInternal.Contains(rowIndex, i)) { DataGridColumn column = dataGrid.ColumnFromDisplayIndex(i); DataGridCellItemAutomationPeer peer = GetOrCreateCellItemPeer(column); if (peer != null) { selectedProviders.Add(ProviderFromPeer(peer)); } } } if (selectedProviders.Count > 0) { return(selectedProviders.ToArray()); } } return(null); }
// This method is called from DataGrid.OnBeginningEdit/OnCommittingEdit/OnCancelingEdit // Raises Invoked event when cell begin/cancel/commit edit internal void RaiseAutomationCellInvokeEvents(DataGridColumn column, DataGridRow row) { DataGridItemAutomationPeer dataGridItemAutomationPeer = GetOrCreateItemPeer(row.Item); if (dataGridItemAutomationPeer != null) { DataGridCellItemAutomationPeer cellPeer = dataGridItemAutomationPeer.GetOrCreateCellItemPeer(column); if (cellPeer != null) { cellPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } } }
internal DataGridCellItemAutomationPeer GetOrCreateCellItemPeer(DataGridColumn column) { DataGridCellItemAutomationPeer peer = null; var peerExists = _itemPeers.TryGetValue(column, out peer); if (!peerExists || peer == null) { peer = new DataGridCellItemAutomationPeer(_item, column); _itemPeers.Add(column, peer); } return(peer); }
private void UpdateEventSource() { DataGridCell cell = (DataGridCell)Owner; DataGrid dataGrid = cell.DataGridOwner; if (dataGrid != null) { DataGridAutomationPeer dataGridAutomationPeer = CreatePeerForElement(dataGrid) as DataGridAutomationPeer; if (dataGridAutomationPeer != null) { DataGridItemAutomationPeer itemAutomationPeer = dataGridAutomationPeer.GetOrCreateItemPeer(cell.DataContext); if (itemAutomationPeer != null) { DataGridCellItemAutomationPeer cellItemAutomationPeer = itemAutomationPeer.GetOrCreateCellItemPeer(cell.Column); this.EventsSource = cellItemAutomationPeer; } } } }
// This method is called from DataGrid.OnSelectedCellsChanged // Raises the selection events when Cell selection changes internal void RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) { // If the result of an AddToSelection or RemoveFromSelection is a single selected cell, // then all we raise is the ElementSelectedEvent for single item if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && this.OwningDataGrid.SelectedCells.Count == 1 && e.AddedCells.Count == 1) { DataGridCellItemAutomationPeer cellPeer = GetCellItemPeer(e.AddedCells[0]); if (cellPeer != null) { cellPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } else { int i; if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)) { for (i = 0; i < e.AddedCells.Count; i++) { DataGridCellItemAutomationPeer cellPeer = GetCellItemPeer(e.AddedCells[i]); if (cellPeer != null) { cellPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } } if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { for (i = 0; i < e.RemovedCells.Count; i++) { DataGridCellItemAutomationPeer cellPeer = GetCellItemPeer(e.RemovedCells[i]); if (cellPeer != null) { cellPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } } }
internal List <AutomationPeer> GetCellItemPeers() { var peers = new List <AutomationPeer>(); var oldChildren = new Dictionary <DataGridColumn, DataGridCellItemAutomationPeer>(_itemPeers); _itemPeers.Clear(); foreach (var column in OwningDataGrid.Columns) { DataGridCellItemAutomationPeer peer = null; var peerExists = oldChildren.TryGetValue(column, out peer); if (!peerExists || peer == null) { peer = new DataGridCellItemAutomationPeer(_item, column); } peers.Add(peer); _itemPeers.Add(column, peer); } return(peers); }
IRawElementProviderSimple IGridProvider.GetItem(int row, int column) { if (row >= 0 && row < this.OwningDataGrid.Items.Count && column >= 0 && column < this.OwningDataGrid.Columns.Count) { object item = this.OwningDataGrid.Items[row]; DataGridColumn dataGridColumn = this.OwningDataGrid.Columns[column]; this.OwningDataGrid.ScrollIntoView(item, dataGridColumn); this.OwningDataGrid.UpdateLayout(); DataGridItemAutomationPeer itemPeer = this.GetOrCreateItemPeer(item); if (itemPeer != null) { DataGridCellItemAutomationPeer cellItemPeer = itemPeer.GetOrCreateCellItemPeer(dataGridColumn); if (cellItemPeer != null) { return(ProviderFromPeer(cellItemPeer)); } } } return(null); }