Example #1
0
        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);
        }
Example #2
0
        internal void UpdateRowPeerEventsSource(DataGridRow row)
        {
            DataGridRowAutomationPeer peer = FromElement(row) as DataGridRowAutomationPeer;

            if (peer != null && row.DataContext != null && _itemPeers.ContainsKey(row.DataContext))
            {
                peer.EventsSource = _itemPeers[row.DataContext];
            }
        }
Example #3
0
        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);
                        }
                    }
                }
            }
        }