private DataGridCellItemAutomationPeer GetOrCreateCellItemPeer(DataGridColumn column, bool addParentInfo)
        {
            DataGridCellItemAutomationPeer dataGridCellItemAutomationPeer = this.CellItemPeers[column];

            if (dataGridCellItemAutomationPeer == null)
            {
                dataGridCellItemAutomationPeer = this.GetPeerFromWeakRefStorage(column);
                if (dataGridCellItemAutomationPeer != null && !addParentInfo)
                {
                    dataGridCellItemAutomationPeer.AncestorsInvalid = false;
                    dataGridCellItemAutomationPeer.ChildrenValid    = false;
                }
            }
            if (dataGridCellItemAutomationPeer == null)
            {
                dataGridCellItemAutomationPeer = new DataGridCellItemAutomationPeer(base.Item, column);
                if (addParentInfo && dataGridCellItemAutomationPeer != null)
                {
                    dataGridCellItemAutomationPeer.TrySetParentInfo(this);
                }
            }
            AutomationPeer owningCellPeer = dataGridCellItemAutomationPeer.OwningCellPeer;

            if (owningCellPeer != null)
            {
                owningCellPeer.EventsSource = dataGridCellItemAutomationPeer;
            }
            return(dataGridCellItemAutomationPeer);
        }
Пример #2
0
        /// <summary>
        /// It returns the CellItemAutomationPeer if it exist corresponding to the item otherwise it creates
        /// one and adds the Handle and parent info by calling AddParentInfo.
        /// </summary>
        /// <param name="column"></param>
        /// <param name="addParentInfo">only required when creating peers for virtualized cells</param>
        /// <returns></returns>
        private DataGridCellItemAutomationPeer GetOrCreateCellItemPeer(DataGridColumn column, bool addParentInfo)
        {
            // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client
            DataGridCellItemAutomationPeer peer = CellItemPeers[column];

            if (peer == null)
            {
                peer = GetPeerFromWeakRefStorage(column);
                if (peer != null && !addParentInfo)
                {
                    // As cached peer is getting used it must be invalidated. addParentInfo check ensures that call is coming from GetChildrenCore
                    peer.AncestorsInvalid = false;
                    peer.ChildrenValid    = false;
                }
            }

            if (peer == null)
            {
                peer = new DataGridCellItemAutomationPeer(Item, column);
                if (addParentInfo && peer != null)
                {
                    peer.TrySetParentInfo(this);
                }
            }

            //perform hookup so the events sourced from wrapper peer are fired as if from the data item
            AutomationPeer wrapperPeer = peer.OwningCellPeer;

            if (wrapperPeer != null)
            {
                wrapperPeer.EventsSource = peer;
            }

            return(peer);
        }
        private DataGridCellItemAutomationPeer GetOrCreateCellItemPeer(DataGridColumn column, bool addParentInfo)
        {
            // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client
            DataGridCellItemAutomationPeer peer = CellItemPeers[column];
            if (peer == null)
            {
                peer = GetPeerFromWeakRefStorage(column);
                if (peer != null && !addParentInfo)
                {
                    // As cached peer is getting used it must be invalidated. addParentInfo check ensures that call is coming from GetChildrenCore
                    peer.AncestorsInvalid = false;
                    peer.ChildrenValid = false;
                }
            }

            if (peer == null)
            {
                peer = new DataGridCellItemAutomationPeer(_item, column);
                if (addParentInfo && peer != null)
                {
                    peer.TrySetParentInfo(this);
                }
            }
            
            //perform hookup so the events sourced from wrapper peer are fired as if from the data item
            AutomationPeer wrapperPeer = peer.OwningCellPeer;
            if (wrapperPeer != null)
            {
                wrapperPeer.EventsSource = peer;
            }

            return peer;
        }