///
        protected override List <AutomationPeer> GetChildrenCore()
        {
            GroupItem    owner        = (GroupItem)Owner;
            ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(Owner);

            if (itemsControl != null)
            {
                ItemsControlAutomationPeer itemsControlAP = itemsControl.CreateAutomationPeer() as ItemsControlAutomationPeer;
                if (itemsControlAP != null)
                {
                    List <AutomationPeer> children = new List <AutomationPeer>();
                    bool useNetFx472CompatibleAccessibilityFeatures = AccessibilitySwitches.UseNetFx472CompatibleAccessibilityFeatures;

                    if (!useNetFx472CompatibleAccessibilityFeatures && owner.Expander != null)
                    {
                        _expanderPeer = UIElementAutomationPeer.CreatePeerForElement(owner.Expander);

                        if (_expanderPeer != null)
                        {
                            _expanderPeer.EventsSource = this;

                            // Call GetChildren so the Expander's toggle button updates its EventsSource as well
                            _expanderPeer.GetChildren();
                        }
                    }
                    Panel itemsHost = owner.ItemsHost;

                    if (itemsHost == null)
                    {
                        if (_expanderPeer == null)
                        {
                            return(null);
                        }
                        else
                        {
                            children.Add(_expanderPeer);
                            return(children);
                        }
                    }

                    IList childItems = itemsHost.Children;
                    ItemPeersStorage <ItemAutomationPeer> addedChildren = new ItemPeersStorage <ItemAutomationPeer>();


                    foreach (UIElement child in childItems)
                    {
                        if (!((MS.Internal.Controls.IGeneratorHost)itemsControl).IsItemItsOwnContainer(child))
                        {
                            UIElementAutomationPeer peer = child.CreateAutomationPeer() as UIElementAutomationPeer;
                            if (peer != null)
                            {
                                children.Add(peer);

                                if (useNetFx472CompatibleAccessibilityFeatures)
                                {
                                    //
                                    // The AncestorsInvalid check is meant so that we do this call to invalidate the
                                    // GroupItemPeers containing the realized item peers only when we arrive here from an
                                    // UpdateSubtree call because that call does not otherwise descend into parts of the tree
                                    // that have their children invalid as an optimization.
                                    //
                                    if (itemsControlAP.RecentlyRealizedPeers.Count > 0 && this.AncestorsInvalid)
                                    {
                                        GroupItemAutomationPeer groupItemPeer = peer as GroupItemAutomationPeer;
                                        if (groupItemPeer != null)
                                        {
                                            groupItemPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(itemsControlAP.RecentlyRealizedPeers);
                                        }
                                    }
                                }
                                else
                                {
                                    //
                                    // The AncestorsInvalid check is meant so that we do this call to invalidate the
                                    // GroupItemPeers only when we arrive here from an
                                    // UpdateSubtree call because that call does not otherwise descend into parts of the tree
                                    // that have their children invalid as an optimization.
                                    //
                                    if (this.AncestorsInvalid)
                                    {
                                        GroupItemAutomationPeer groupItemPeer = peer as GroupItemAutomationPeer;
                                        if (groupItemPeer != null)
                                        {
                                            // invalidate all GroupItemAP children, so
                                            // that the top-level ItemsControlAP's
                                            // ItemPeers collection is repopulated.
                                            groupItemPeer.AncestorsInvalid = true;
                                            groupItemPeer.ChildrenValid    = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            object item = itemsControl.ItemContainerGenerator.ItemFromContainer(child);

                            // ItemFromContainer can return {UnsetValue} if we're in a re-entrant
                            // call while the generator is in the midst of unhooking the container.
                            // Ignore such children.
                            if (item == DependencyProperty.UnsetValue)
                            {
                                continue;
                            }

                            // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client
                            ItemAutomationPeer peer = useNetFx472CompatibleAccessibilityFeatures
                                                        ? itemsControlAP.ItemPeers[item]
                                                        : itemsControlAP.ReusablePeerFor(item);

                            peer = itemsControlAP.ReusePeerForItem(peer, item);

                            if (peer != null)
                            {
                                if (useNetFx472CompatibleAccessibilityFeatures)
                                {
                                    //
                                    // We have now connected the realized peer to its actual parent. Hence the cache can be cleared
                                    //
                                    int realizedPeerIndex = itemsControlAP.RecentlyRealizedPeers.IndexOf(peer);
                                    if (realizedPeerIndex >= 0)
                                    {
                                        itemsControlAP.RecentlyRealizedPeers.RemoveAt(realizedPeerIndex);
                                    }
                                }
                            }
                            else
                            {
                                peer = itemsControlAP.CreateItemAutomationPeerInternal(item);
                            }

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

                            //protection from indistinguishable items - for example, 2 strings with same value
                            //this scenario does not work in ItemsControl however is not checked for.
                            //  Our parent's ItemPeerStorage collection may not have been cleared,
                            // this would cause us to report 0 children, if the peer is already in the collection
                            // check its parent, if it has been set to us, we should add it to the return collection,
                            // but only if we haven't added a peer for this item during this GetChildrenCore call.
                            bool itemMissingPeerInGlobalStorage = itemsControlAP.ItemPeers[item] == null;

                            if (peer != null && (itemMissingPeerInGlobalStorage ||
                                                 (peer.GetParent() == this && addedChildren[item] == null)))
                            {
                                children.Add(peer);
                                addedChildren[item] = peer;

                                if (itemMissingPeerInGlobalStorage)
                                {
                                    itemsControlAP.ItemPeers[item] = peer;
                                }
                            }
                        }
                    }

                    return(children);
                }
            }

            return(null);
        }
        /// <summary>Gets the collection of child elements of the <see cref="T:System.Windows.Controls.GroupItem" /> that is associated with this <see cref="T:System.Windows.Automation.Peers.GroupItemAutomationPeer" />. This method is called by <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetChildren" />.</summary>
        /// <returns>The collection of child elements.</returns>
        // Token: 0x060026E9 RID: 9961 RVA: 0x000B8530 File Offset: 0x000B6730
        protected override List <AutomationPeer> GetChildrenCore()
        {
            GroupItem    groupItem    = (GroupItem)base.Owner;
            ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(base.Owner);

            if (itemsControl != null)
            {
                ItemsControlAutomationPeer itemsControlAutomationPeer = itemsControl.CreateAutomationPeer() as ItemsControlAutomationPeer;
                if (itemsControlAutomationPeer != null)
                {
                    Panel itemsHost = groupItem.ItemsHost;
                    if (itemsHost == null)
                    {
                        return(null);
                    }
                    IList children             = itemsHost.Children;
                    List <AutomationPeer> list = new List <AutomationPeer>(children.Count);
                    ItemPeersStorage <ItemAutomationPeer> itemPeersStorage = new ItemPeersStorage <ItemAutomationPeer>();
                    bool useNetFx472CompatibleAccessibilityFeatures        = AccessibilitySwitches.UseNetFx472CompatibleAccessibilityFeatures;
                    if (!useNetFx472CompatibleAccessibilityFeatures && groupItem.Expander != null)
                    {
                        this._expanderPeer = UIElementAutomationPeer.CreatePeerForElement(groupItem.Expander);
                        if (this._expanderPeer != null)
                        {
                            this._expanderPeer.EventsSource = this;
                            this._expanderPeer.GetChildren();
                        }
                    }
                    foreach (object obj in children)
                    {
                        UIElement uielement = (UIElement)obj;
                        if (!((IGeneratorHost)itemsControl).IsItemItsOwnContainer(uielement))
                        {
                            UIElementAutomationPeer uielementAutomationPeer = uielement.CreateAutomationPeer() as UIElementAutomationPeer;
                            if (uielementAutomationPeer != null)
                            {
                                list.Add(uielementAutomationPeer);
                                if (useNetFx472CompatibleAccessibilityFeatures)
                                {
                                    if (itemsControlAutomationPeer.RecentlyRealizedPeers.Count > 0 && this.AncestorsInvalid)
                                    {
                                        GroupItemAutomationPeer groupItemAutomationPeer = uielementAutomationPeer as GroupItemAutomationPeer;
                                        if (groupItemAutomationPeer != null)
                                        {
                                            groupItemAutomationPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(itemsControlAutomationPeer.RecentlyRealizedPeers);
                                        }
                                    }
                                }
                                else if (this.AncestorsInvalid)
                                {
                                    GroupItemAutomationPeer groupItemAutomationPeer2 = uielementAutomationPeer as GroupItemAutomationPeer;
                                    if (groupItemAutomationPeer2 != null)
                                    {
                                        groupItemAutomationPeer2.AncestorsInvalid = true;
                                        groupItemAutomationPeer2.ChildrenValid    = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            object obj2 = itemsControl.ItemContainerGenerator.ItemFromContainer(uielement);
                            if (obj2 != DependencyProperty.UnsetValue)
                            {
                                ItemAutomationPeer itemAutomationPeer = useNetFx472CompatibleAccessibilityFeatures ? itemsControlAutomationPeer.ItemPeers[obj2] : itemsControlAutomationPeer.ReusablePeerFor(obj2);
                                itemAutomationPeer = itemsControlAutomationPeer.ReusePeerForItem(itemAutomationPeer, obj2);
                                if (itemAutomationPeer != null)
                                {
                                    if (useNetFx472CompatibleAccessibilityFeatures)
                                    {
                                        int num = itemsControlAutomationPeer.RecentlyRealizedPeers.IndexOf(itemAutomationPeer);
                                        if (num >= 0)
                                        {
                                            itemsControlAutomationPeer.RecentlyRealizedPeers.RemoveAt(num);
                                        }
                                    }
                                }
                                else
                                {
                                    itemAutomationPeer = itemsControlAutomationPeer.CreateItemAutomationPeerInternal(obj2);
                                }
                                if (itemAutomationPeer != null)
                                {
                                    AutomationPeer wrapperPeer = itemAutomationPeer.GetWrapperPeer();
                                    if (wrapperPeer != null)
                                    {
                                        wrapperPeer.EventsSource = itemAutomationPeer;
                                        if (itemAutomationPeer.ChildrenValid && itemAutomationPeer.Children == null && this.AncestorsInvalid)
                                        {
                                            itemAutomationPeer.AncestorsInvalid = true;
                                            wrapperPeer.AncestorsInvalid        = true;
                                        }
                                    }
                                }
                                bool flag = itemsControlAutomationPeer.ItemPeers[obj2] == null;
                                if (itemAutomationPeer != null && (flag || (itemAutomationPeer.GetParent() == this && itemPeersStorage[obj2] == null)))
                                {
                                    list.Add(itemAutomationPeer);
                                    itemPeersStorage[obj2] = itemAutomationPeer;
                                    if (flag)
                                    {
                                        itemsControlAutomationPeer.ItemPeers[obj2] = itemAutomationPeer;
                                    }
                                }
                            }
                        }
                    }
                    return(list);
                }
            }
            return(null);
        }