public DataGridItemCellAutomationPeer( DataGridItemAutomationPeer itemAutomationPeer, ColumnBase column ) { if( itemAutomationPeer == null ) throw new ArgumentNullException( "itemAutomationPeer" ); if( column == null ) throw new ArgumentNullException( "column" ); m_itemAutomationPeer = itemAutomationPeer; m_column = column; // Call the GetWrapperPeer since it will force the events of the wrapped peer to be rerooted to us. AutomationPeer wrapperPeer = this.GetWrapperPeer(); }
private static void OnIsSelectedChanged(object sender, DependencyPropertyChangedEventArgs e) { DataGridRow row = (DataGridRow)sender; bool isSelected = (bool)e.NewValue; if (isSelected && !row.IsSelectable) { throw new InvalidOperationException(SR.Get(SRID.DataGridRow_CannotSelectRowWhenCells)); } DataGrid grid = row.DataGridOwner; if (grid != null && row.DataContext != null) { DataGridAutomationPeer gridPeer = UIElementAutomationPeer.FromElement(grid) as DataGridAutomationPeer; if (gridPeer != null) { DataGridItemAutomationPeer rowItemPeer = gridPeer.GetOrCreateItemPeer(row.DataContext); if (rowItemPeer != null) { rowItemPeer.RaisePropertyChangedEvent( System.Windows.Automation.SelectionItemPatternIdentifiers.IsSelectedProperty, (bool)e.OldValue, isSelected); } } } // Update the header's IsRowSelected property row.NotifyPropertyChanged(row, e, NotificationTarget.Rows | NotificationTarget.RowHeaders); // This will raise the appropriate selection event, which will // bubble to the DataGrid. The base class Selector code will listen // for these events and will update SelectedItems as necessary. row.RaiseSelectionChangedEvent(isSelected); }
// Return automation peer corresponding to the row data item internal DataGridItemAutomationPeer GetOrCreateItemPeer(object item) { DataGridItemAutomationPeer peer = null; bool peerExists = _itemPeers.TryGetValue(item, out peer); if (!peerExists || peer == null) { peer = new DataGridItemAutomationPeer(item, this.OwningDataGrid); _itemPeers.Add(item, peer); } return peer; }
// Return a list of automation peer corresponding to all rows in the DataGrid private List<AutomationPeer> GetItemPeers() { List<AutomationPeer> peers = new List<AutomationPeer>(); Dictionary<object, DataGridItemAutomationPeer> oldChildren = new Dictionary<object, DataGridItemAutomationPeer>(_itemPeers); _itemPeers.Clear(); foreach (object item in this.OwningDataGrid.Items) { DataGridItemAutomationPeer peer = null; bool peerExists = oldChildren.TryGetValue(item, out peer); if (!peerExists || peer == null) { peer = new DataGridItemAutomationPeer(item, this.OwningDataGrid); } peers.Add(peer); _itemPeers.Add(item, peer); } return peers; }