internal DataGridItemAutomationPeer GetOrCreateItemPeer(object item) { DataGridItemAutomationPeer peer = null; if (item != null) { if (_itemPeers.ContainsKey(item)) { peer = _itemPeers[item]; } else { peer = new DataGridItemAutomationPeer(item, this.OwningDataGrid); _itemPeers.Add(item, peer); } DataGridRowAutomationPeer rowPeer = peer.OwningRowPeer; if (rowPeer != null) { rowPeer.EventsSource = peer; } } return(peer); }
IRawElementProviderSimple[] ISelectionProvider.GetSelection() { EnsureEnabled(); if (this.OwningDataGrid != null && this.OwningDataGridPeer != null && this.OwningDataGrid.SelectedItems != null && _group.GroupItems.Count /*ItemCount*/ > 0) { DataGridRowGroupInfo groupInfo = this.OwningDataGrid.RowGroupInfoFromCollectionViewGroup(_group); if (groupInfo != null) { // See which of the selected items are contained within this group List <IRawElementProviderSimple> selectedProviders = new List <IRawElementProviderSimple>(); int startRowIndex = groupInfo.Slot - this.OwningDataGrid.RowGroupHeadersTable.GetIndexCount(0, groupInfo.Slot) + 1; foreach (object item in this.OwningDataGrid.GetSelectionInclusive(startRowIndex, startRowIndex + _group.GroupItems.Count /*ItemCount*/ - 1)) { DataGridItemAutomationPeer peer = this.OwningDataGridPeer.GetOrCreateItemPeer(item); if (peer != null) { selectedProviders.Add(ProviderFromPeer(peer)); } } return(selectedProviders.ToArray()); } } return(null); }
internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e) { // 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) && this.OwningDataGrid.SelectedItems.Count == 1) { if (this.OwningDataGrid.SelectedItem != null && _itemPeers.ContainsKey(this.OwningDataGrid.SelectedItem)) { DataGridItemAutomationPeer peer = _itemPeers[this.OwningDataGrid.SelectedItem]; #if DEBUG_AUTOMATION Debug.WriteLine("DataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected)"); #endif peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } else { int i; if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)) { for (i = 0; i < e.AddedItems.Count; i++) { if (e.AddedItems[i] != null && _itemPeers.ContainsKey(e.AddedItems[i])) { DataGridItemAutomationPeer peer = _itemPeers[e.AddedItems[i]]; #if DEBUG_AUTOMATION Debug.WriteLine("DataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)"); #endif peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } } if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { for (i = 0; i < e.RemovedItems.Count; i++) { if (e.RemovedItems[i] != null && _itemPeers.ContainsKey(e.RemovedItems[i])) { DataGridItemAutomationPeer peer = _itemPeers[e.RemovedItems[i]]; #if DEBUG_AUTOMATION Debug.WriteLine("DataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)"); #endif peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } } }
IRawElementProviderSimple[] ISelectionProvider.GetSelection() { if (this.OwningDataGrid != null && this.OwningDataGrid.SelectedItems != null) { List <IRawElementProviderSimple> selectedProviders = new List <IRawElementProviderSimple>(); foreach (object item in this.OwningDataGrid.SelectedItems) { DataGridItemAutomationPeer peer = GetOrCreateItemPeer(item); if (peer != null) { selectedProviders.Add(ProviderFromPeer(peer)); } } return(selectedProviders.ToArray()); } return(null); }
internal void PopulateItemPeers() { Dictionary <object, DataGridItemAutomationPeer> oldChildren = new Dictionary <object, DataGridItemAutomationPeer>(_itemPeers); _itemPeers.Clear(); if (this.OwningDataGrid.ItemsSource != null) { foreach (object item in this.OwningDataGrid.ItemsSource) { if (item != null) { DataGridItemAutomationPeer peer = null; if (oldChildren.ContainsKey(item)) { peer = oldChildren[item] as DataGridItemAutomationPeer; } else { peer = new DataGridItemAutomationPeer(item, this.OwningDataGrid); } if (peer != null) { DataGridRowAutomationPeer rowPeer = peer.OwningRowPeer; if (rowPeer != null) { rowPeer.EventsSource = peer; } } // This guards against the addition of duplicate items if (!_itemPeers.ContainsKey(item)) { _itemPeers.Add(item, peer); } } } } }
internal void RaiseAutomationInvokeEvents(DataGridEditingUnit editingUnit, DataGridColumn column, DataGridRow row) { switch (editingUnit) { case DataGridEditingUnit.Cell: { DataGridCell cell = row.Cells[column.Index]; AutomationPeer peer = FromElement(cell); if (peer != null) { peer.InvalidatePeer(); } else { peer = CreatePeerForElement(cell); } if (peer != null) { #if DEBUG_AUTOMATION Debug.WriteLine(peer.ToString() + ".RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked)"); #endif peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } break; } case DataGridEditingUnit.Row: { DataGridItemAutomationPeer peer = GetOrCreateItemPeer(row.DataContext); #if DEBUG_AUTOMATION Debug.WriteLine("DataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked)"); #endif peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); break; } } }