//
        private static bool iterate(TreeViewItemAutomationPeer logicalParentAp, DependencyObject parent, IteratorCallback callback, ItemPeersStorage<ItemAutomationPeer> dataChildren, ItemPeersStorage<ItemAutomationPeer> oldChildren)
        { 
            bool done = false;
 
            if (parent != null) 
            {
                AutomationPeer peer = null; 
                int count = VisualTreeHelper.GetChildrenCount(parent);
                for (int i = 0; i < count && !done; i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(parent, i); 

                    if (child != null 
                        && child is UIElement) 
                    {
                        if (child is TreeViewItem) 
                        {
                            object dataItem = (child as UIElement) != null ? (logicalParentAp.Owner as ItemsControl).GetItemOrContainerFromContainer(child as UIElement) : child;
                            peer = oldChildren[dataItem];
 
                            if (peer == null)
                            { 
                                peer = logicalParentAp.GetPeerFromWeakRefStorage(dataItem); 
                                if (peer != null)
                                { 
                                    // As cached peer is getting used it must be invalidated.
                                    peer.AncestorsInvalid = false;
                                    peer.ChildrenValid = false;
                                } 
                            }
 
                            if (peer == null) 
                            {
                                peer = logicalParentAp.CreateItemAutomationPeer(dataItem); 
                            }

                            //perform hookup so the events sourced from wrapper peer are fired as if from the data item
                            if (peer != null) 
                            {
                                AutomationPeer wrapperPeer = (peer as ItemAutomationPeer).GetWrapperPeer(); 
                                if (wrapperPeer != null) 
                                {
                                    wrapperPeer.EventsSource = peer; 
                                }

                                if (dataChildren[dataItem] == null && peer is ItemAutomationPeer)
                                { 
                                    callback(peer);
                                    dataChildren[dataItem] = peer as ItemAutomationPeer; 
                                } 
                            }
                        } 
                        else
                        {
                            peer = CreatePeerForElement((UIElement)child);
 
                            if (peer != null)
                                done = callback(peer); 
                        } 

                        if(peer == null) 
                            done = iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                    }
                    else
                    { 
                        done = iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                    } 
                } 
            }
 
            return done;
        }
Пример #2
0
        //
        private static bool iterate(TreeViewItemAutomationPeer logicalParentAp, DependencyObject parent, IteratorCallback callback, ItemPeersStorage <ItemAutomationPeer> dataChildren, ItemPeersStorage <ItemAutomationPeer> oldChildren)
        {
            bool done = false;

            if (parent != null)
            {
                AutomationPeer peer  = null;
                int            count = VisualTreeHelper.GetChildrenCount(parent);
                for (int i = 0; i < count && !done; i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(parent, i);

                    if (child != null &&
                        child is UIElement)
                    {
                        if (child is TreeViewItem)
                        {
                            object dataItem = (child as UIElement) != null ? (logicalParentAp.Owner as ItemsControl).GetItemOrContainerFromContainer(child as UIElement) : child;
                            peer = oldChildren[dataItem];

                            if (peer == null)
                            {
                                peer = logicalParentAp.GetPeerFromWeakRefStorage(dataItem);
                                if (peer != null)
                                {
                                    // As cached peer is getting used it must be invalidated.
                                    peer.AncestorsInvalid = false;
                                    peer.ChildrenValid    = false;
                                }
                            }

                            if (peer == null)
                            {
                                peer = logicalParentAp.CreateItemAutomationPeer(dataItem);
                            }

                            //perform hookup so the events sourced from wrapper peer are fired as if from the data item
                            if (peer != null)
                            {
                                AutomationPeer wrapperPeer = (peer as ItemAutomationPeer).GetWrapperPeer();
                                if (wrapperPeer != null)
                                {
                                    wrapperPeer.EventsSource = peer;
                                }

                                if (dataChildren[dataItem] == null && peer is ItemAutomationPeer)
                                {
                                    callback(peer);
                                    dataChildren[dataItem] = peer as ItemAutomationPeer;
                                }
                            }
                        }
                        else
                        {
                            peer = CreatePeerForElement((UIElement)child);

                            if (peer != null)
                            {
                                done = callback(peer);
                            }
                        }

                        if (peer == null)
                        {
                            done = iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                        }
                    }
                    else
                    {
                        done = iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                    }
                }
            }

            return(done);
        }
        // Token: 0x06002885 RID: 10373 RVA: 0x000BC954 File Offset: 0x000BAB54
        private static bool iterate(TreeViewItemAutomationPeer logicalParentAp, DependencyObject parent, TreeViewItemAutomationPeer.IteratorCallback callback, ItemPeersStorage <ItemAutomationPeer> dataChildren, ItemPeersStorage <ItemAutomationPeer> oldChildren)
        {
            bool flag = false;

            if (parent != null)
            {
                int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
                int num           = 0;
                while (num < childrenCount && !flag)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(parent, num);
                    if (child != null && child is UIElement)
                    {
                        AutomationPeer automationPeer;
                        if (child is TreeViewItem)
                        {
                            object item = (child is UIElement) ? (logicalParentAp.Owner as ItemsControl).GetItemOrContainerFromContainer(child as UIElement) : child;
                            automationPeer = oldChildren[item];
                            if (automationPeer == null)
                            {
                                automationPeer = logicalParentAp.GetPeerFromWeakRefStorage(item);
                                if (automationPeer != null)
                                {
                                    automationPeer.AncestorsInvalid = false;
                                    automationPeer.ChildrenValid    = false;
                                }
                            }
                            if (automationPeer == null)
                            {
                                automationPeer = logicalParentAp.CreateItemAutomationPeer(item);
                            }
                            if (automationPeer != null)
                            {
                                AutomationPeer wrapperPeer = (automationPeer as ItemAutomationPeer).GetWrapperPeer();
                                if (wrapperPeer != null)
                                {
                                    wrapperPeer.EventsSource = automationPeer;
                                }
                                if (dataChildren[item] == null && automationPeer is ItemAutomationPeer)
                                {
                                    callback(automationPeer);
                                    dataChildren[item] = (automationPeer as ItemAutomationPeer);
                                }
                            }
                        }
                        else
                        {
                            automationPeer = UIElementAutomationPeer.CreatePeerForElement((UIElement)child);
                            if (automationPeer != null)
                            {
                                flag = callback(automationPeer);
                            }
                        }
                        if (automationPeer == null)
                        {
                            flag = TreeViewItemAutomationPeer.iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                        }
                    }
                    else
                    {
                        flag = TreeViewItemAutomationPeer.iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                    }
                    num++;
                }
            }
            return(flag);
        }