Example #1
0
        private void AddChildrenHeaders(
            HeadersFootersGeneratorNode headerNode,
            Hashtable oldHeaderFooterChildren,
            List <AutomationPeer> list)
        {
            if (m_parentDataGridContext == null)
            {
                // Add fixed header to the children list
                Panel fixedHeaderPanel = m_dataGridControl.FixedHeadersHostPanel;

                if (fixedHeaderPanel != null)
                {
                    int index = 0;

                    foreach (DependencyObject headerFooter in fixedHeaderPanel.Children)
                    {
                        HeaderFooterItem headerFooterItem = headerFooter as HeaderFooterItem;

                        if (headerFooterItem != null)
                        {
                            HeaderFooterItemAutomationPeer automationPeer = oldHeaderFooterChildren[headerFooter] as HeaderFooterItemAutomationPeer;

                            if (automationPeer == null)
                            {
                                automationPeer = new HeaderFooterItemAutomationPeer(m_dataGridContext, headerFooter);
                            }

                            automationPeer.SetExtraInfo(HeaderFooterItemAutomationPeer.HeaderFooterType.FixedHeader, index);
                            m_headerFooterChildren[headerFooter] = automationPeer;
                            list.Add(automationPeer);
                        }

                        index++;
                    }
                }
            }

            if (headerNode != null)
            {
                DataGridGroupAutomationPeer.AddHeaderPeer(m_dataGridContext, headerNode, list, m_headerFooterChildren, oldHeaderFooterChildren);
            }
        }
        protected override List <AutomationPeer> GetChildrenCore()
        {
            Group owner = this.Owner;
            GroupGeneratorNode generatorNode = owner.GeneratorNode;

            if (generatorNode == null)
            {
                return(null);
            }

            DataGridContext dataGridContext = owner.DataGridContext;

            if (dataGridContext == null)
            {
                return(null);
            }

            CustomItemContainerGenerator customItemContainerGenerator = dataGridContext.CustomItemContainerGenerator;
            IList <object> items;
            bool           itemsIsAllItems = false;

            // The way Microsoft check if we are called by an automation that support Virtualization.
            if ((ItemContainerPatternIdentifiers.Pattern != null) && (owner.IsBottomLevel) && (dataGridContext.DataGridControl.ItemsHost is DataGridItemsHost))
            {
                items = customItemContainerGenerator.GetRealizedDataItemsForGroup(generatorNode);
            }
            else
            {
                items           = owner.GetItems();
                itemsIsAllItems = true;
            }

            int       itemsCount              = (items == null) ? 0 : items.Count;
            Hashtable oldDataChildren         = m_dataChildren;
            Hashtable oldHeaderFooterChildren = m_headerFooterChildren;

            // Get header count
            HeadersFootersGeneratorNode headerNode = generatorNode.GetHeaderNode();
            int headersCount = (headerNode == null) ? 0 : headerNode.ItemCount;

            // Get footer count
            HeadersFootersGeneratorNode footerNode = generatorNode.GetFooterNode();
            int footersCount = (footerNode == null) ? 0 : footerNode.ItemCount;

            int childrenCount = itemsCount + headersCount + footersCount;

            m_dataChildren         = new Hashtable(itemsCount);
            m_headerFooterChildren = new Hashtable(headersCount + footersCount);

            if (childrenCount == 0)
            {
                return(null);
            }

            DataGridContextAutomationPeer dataGridContextAutomationPeer = dataGridContext.Peer;
            Hashtable dataGridContextItemsPeer = dataGridContextAutomationPeer.ItemPeers;

            DataGridGroupAutomationPeer groupAutomationPeer;
            DataGridItemAutomationPeer  itemAutomationPeer;
            List <AutomationPeer>       list = new List <AutomationPeer>(childrenCount);

            if (headerNode != null)
            {
                DataGridGroupAutomationPeer.AddHeaderPeer(dataGridContext, headerNode, list, m_headerFooterChildren, oldHeaderFooterChildren);
            }

            int index = 0;

            for (int i = 0; i < itemsCount; i++)
            {
                object item = items[i];
                CollectionViewGroup collectionViewGroup = item as CollectionViewGroup;

                if (collectionViewGroup == null)
                {
                    if ((i == 0) && (itemsIsAllItems))
                    {
                        GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper(generatorNode, 0, 0);
                        nodeHelper.ReverseCalculateIndex();
                        index = nodeHelper.SourceDataIndex;
                    }

                    itemAutomationPeer = oldDataChildren[item] as DataGridItemAutomationPeer;

                    if (itemAutomationPeer == null)
                    {
                        if (itemsIsAllItems)
                        {
                            itemAutomationPeer = dataGridContextAutomationPeer.CreateItemAutomationPeerInternal(item, index + i);
                        }
                        else
                        {
                            itemAutomationPeer = dataGridContextAutomationPeer.CreateItemAutomationPeerInternal(item, -1);
                        }
                    }
                    else
                    {
                        if (itemsIsAllItems)
                        {
                            itemAutomationPeer.SetIndex(index + i);
                        }
                        else
                        {
                            itemAutomationPeer.SetIndex(-1);
                        }
                    }

                    // Force EventsSource to be updated
                    itemAutomationPeer.GetWrapperPeer();

                    if (m_dataChildren[item] == null)
                    {
                        Debug.Assert(itemAutomationPeer != null);
                        list.Add(itemAutomationPeer);
                        m_dataChildren[item] = itemAutomationPeer;

                        if (dataGridContextItemsPeer[item] == null)
                        {
                            dataGridContextItemsPeer[item] = itemAutomationPeer;
                        }
                    }
                }
                else
                {
                    Group uiGroup =
                        customItemContainerGenerator.GetGroupFromCollectionViewGroup(this.Owner, collectionViewGroup);

                    if (uiGroup != null)
                    {
                        groupAutomationPeer = uiGroup.CreateAutomationPeer() as DataGridGroupAutomationPeer;

                        if (groupAutomationPeer != null)
                        {
                            list.Add(groupAutomationPeer);
                        }
                    }
                }
            }

            if (footerNode != null)
            {
                DataGridGroupAutomationPeer.AddFooterPeer(dataGridContext, footerNode, list, m_headerFooterChildren, oldHeaderFooterChildren);
            }

            return(list);
        }