// This method is called from DataGrid.OnBeginningEdit/OnCommittingEdit/OnCancelingEdit // Raises Invoked event when row begin/cancel/commit edit internal void RaiseAutomationRowInvokeEvents(DataGridRow row) { DataGridItemAutomationPeer dataGridItemAutomationPeer = GetOrCreateItemPeer(row.Item); if (dataGridItemAutomationPeer != null) { dataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } }
// This method is called from DataGrid.OnSelectionChanged // Raises the selection events when Items selection changes internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e) { int numSelected = this.OwningDataGrid.SelectedItems.Count; int numAdded = e.AddedItems.Count; // If the result of an AddToSelection or RemoveFromSelection is a single selected item, // then all we raise is the ElementSelectedEvent for single item if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && numSelected == 1 && numAdded == 1) { DataGridItemAutomationPeer peer = GetOrCreateItemPeer(this.OwningDataGrid.SelectedItem); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } else { int i; if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)) { for (i = 0; i < e.AddedItems.Count; i++) { DataGridItemAutomationPeer peer = GetOrCreateItemPeer(e.AddedItems[i]); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } } if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { for (i = 0; i < e.RemovedItems.Count; i++) { DataGridItemAutomationPeer peer = GetOrCreateItemPeer(e.RemovedItems[i]); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } } }