示例#1
0
        // Return value for specified property; or null if not supported
        private object InContextGetPropertyValue(object arg)
        {
            AutomationPeer peer = Peer;

            if (peer == null)
            {
                throw new ElementNotAvailableException();
            }
            return(peer.GetPropertyValue((int)arg));
        }
        public IRawElementProviderSimple FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            if ((propertyId != 0) && (!DataGridGroupAutomationPeer.IsPropertySupportedForFindItem(propertyId)))
            {
                throw new ArgumentException("Property not supported");
            }

            Group owner = this.Owner;
            GroupGeneratorNode generatorNode = owner.GeneratorNode;

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

            DataGridContext dataGridContext = owner.DataGridContext;

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

            this.ResetChildrenCache();
            IList <object> items      = owner.GetItems();
            int            itemsCount = (items == null) ? 0 : items.Count;

            DataGridItemAutomationPeer     startAfterItemPeer         = null;
            HeaderFooterItemAutomationPeer startAfterHeaderFooterPeer = null;

            if (startAfter != null)
            {
                AutomationPeer startAfterPeer = this.PeerFromProvider(startAfter);

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

                startAfterItemPeer         = startAfterPeer as DataGridItemAutomationPeer;
                startAfterHeaderFooterPeer = startAfterPeer as HeaderFooterItemAutomationPeer;
            }

            int startIndex = 0;

            // 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 = headersCount + footersCount + itemsCount;

            if (startAfterItemPeer != null)
            {
                startIndex = headersCount + startAfterItemPeer.Index + 1;
            }
            else if (startAfterHeaderFooterPeer != null)
            {
                startIndex = startAfterHeaderFooterPeer.Index + 1;

                switch (startAfterHeaderFooterPeer.Type)
                {
                case HeaderFooterItemAutomationPeer.HeaderFooterType.Header:
                {
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.Footer:
                {
                    startIndex += headersCount + itemsCount;
                    break;
                }
                }
            }

            if (propertyId == 0)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(startIndex);

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

                return(this.ProviderFromPeer(peer));
            }

            object propertyValue = null;

            for (int i = startIndex; i < childrenCount; i++)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(i);

                if (peer != null)
                {
                    try
                    {
                        propertyValue = peer.GetPropertyValue(propertyId);
                    }
                    catch (Exception exception)
                    {
                        if (exception is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (object.Equals(value, propertyValue))
                    {
                        return(this.ProviderFromPeer(peer));
                    }
                }
            }

            return(null);
        }
        public IRawElementProviderSimple FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            if ((propertyId != 0) && (!DataGridContextAutomationPeer.IsPropertySupportedForFindItem(propertyId)))
            {
                throw new ArgumentException("Property not supported");
            }

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

            CollectionView items      = m_dataGridContext.Items;
            int            itemsCount = (items == null) ? 0 : items.Count;

            DataGridItemAutomationPeer     startAfterItemPeer         = null;
            HeaderFooterItemAutomationPeer startAfterHeaderFooterPeer = null;

            if (startAfter != null)
            {
                AutomationPeer startAfterPeer = this.PeerFromProvider(startAfter);

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

                startAfterItemPeer         = startAfterPeer as DataGridItemAutomationPeer;
                startAfterHeaderFooterPeer = startAfterPeer as HeaderFooterItemAutomationPeer;
            }

            int startIndex = 0;

            // Get header count
            HeadersFootersGeneratorNode headerNode = m_dataGridContext.CustomItemContainerGenerator.Header;
            int   headersCount      = (headerNode == null) ? 0 : headerNode.ItemCount;
            int   fixedHeadersCount = 0;
            Panel fixedHeadersPanel = null;

            // Get footer count
            HeadersFootersGeneratorNode footerNode = m_dataGridContext.CustomItemContainerGenerator.Footer;
            int   footersCount      = (footerNode == null) ? 0 : footerNode.ItemCount;
            int   fixedFootersCount = 0;
            Panel fixedFootersPanel = null;

            if (m_parentDataGridContext == null)
            {
                // Add the fixed header / footer count to the children
                fixedHeadersPanel = m_dataGridControl.FixedHeadersHostPanel;
                fixedHeadersCount = (fixedHeadersPanel != null) ? fixedHeadersPanel.Children.Count : 0;
                fixedFootersPanel = m_dataGridControl.FixedFootersHostPanel;
                fixedFootersCount = (fixedFootersPanel != null) ? fixedFootersPanel.Children.Count : 0;
            }

            int childrenCount = headersCount + fixedHeadersCount + footersCount + fixedFootersCount + itemsCount;

            if (startAfterItemPeer != null)
            {
                startIndex = fixedHeadersCount + headersCount + startAfterItemPeer.Index + 1;
            }
            else if (startAfterHeaderFooterPeer != null)
            {
                startIndex = startAfterHeaderFooterPeer.Index + 1;

                switch (startAfterHeaderFooterPeer.Type)
                {
                case HeaderFooterItemAutomationPeer.HeaderFooterType.FixedHeader:
                {
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.Header:
                {
                    startIndex += fixedHeadersCount;
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.Footer:
                {
                    startIndex += fixedHeadersCount + headersCount + itemsCount;
                    break;
                }

                case HeaderFooterItemAutomationPeer.HeaderFooterType.FixedFooter:
                {
                    startIndex += fixedHeadersCount + headersCount + footersCount + itemsCount;
                    break;
                }
                }
            }

            // Force a children refresh and update our inner caching
            this.GetChildren();

            if (propertyId == 0)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(startIndex);

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

                return(this.ProviderFromPeer(peer));
            }

            object propertyValue = null;

            // Search in footer/Fixed footer first
            if (footersCount + fixedFootersCount > 0)
            {
                int footerStartIndex = Math.Max(startIndex, childrenCount - footersCount - fixedFootersCount);

                for (int i = startIndex; i < childrenCount; i++)
                {
                    AutomationPeer peer = this.GetPeerForChildrenIndex(i);

                    if (peer != null)
                    {
                        try
                        {
                            propertyValue = peer.GetPropertyValue(propertyId);
                        }
                        catch (Exception exception)
                        {
                            if (exception is ElementNotAvailableException)
                            {
                                continue;
                            }
                        }

                        if (object.Equals(value, propertyValue))
                        {
                            return(this.ProviderFromPeer(peer));
                        }
                    }
                }

                childrenCount -= footersCount + fixedFootersCount;
            }

            // Search in the header/Fixed header and data item
            for (int i = startIndex; i < childrenCount; i++)
            {
                AutomationPeer peer = this.GetPeerForChildrenIndex(i);

                if (peer != null)
                {
                    try
                    {
                        propertyValue = peer.GetPropertyValue(propertyId);
                    }
                    catch (Exception exception)
                    {
                        if (exception is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (object.Equals(value, propertyValue))
                    {
                        return(this.ProviderFromPeer(peer));
                    }
                }
            }

            return(null);
        }