/// <summary>Retrieves an element by the specified property value.</summary>
        /// <param name="startAfter">The item in the container after which to begin the search.</param>
        /// <param name="propertyId">The property that contains the value to retrieve.</param>
        /// <param name="value">The value to retrieve.</param>
        /// <returns>The first item that matches the search criterion; otherwise, <see langword="null" /> if no items match.</returns>
        // Token: 0x060025E9 RID: 9705 RVA: 0x000B5858 File Offset: 0x000B3A58
        IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            base.ResetChildrenCache();
            if (propertyId != 0 && !SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId))
            {
                throw new ArgumentException(SR.Get("PropertyNotSupported"));
            }
            IList <DataGridColumn> columns = this.OwningDataGrid.Columns;

            if (columns != null && columns.Count > 0)
            {
                DataGridCellItemAutomationPeer dataGridCellItemAutomationPeer = null;
                if (startAfter != null)
                {
                    dataGridCellItemAutomationPeer = (base.PeerFromProvider(startAfter) as DataGridCellItemAutomationPeer);
                }
                int num = 0;
                if (dataGridCellItemAutomationPeer != null)
                {
                    if (dataGridCellItemAutomationPeer.Column == null)
                    {
                        throw new InvalidOperationException(SR.Get("InavalidStartItem"));
                    }
                    num = columns.IndexOf(dataGridCellItemAutomationPeer.Column) + 1;
                    if (num == 0 || num == columns.Count)
                    {
                        return(null);
                    }
                }
                if (propertyId == 0 && num < columns.Count)
                {
                    return(base.ProviderFromPeer(this.GetOrCreateCellItemPeer(columns[num])));
                }
                object obj = null;
                for (int i = num; i < columns.Count; i++)
                {
                    DataGridCellItemAutomationPeer orCreateCellItemPeer = this.GetOrCreateCellItemPeer(columns[i]);
                    if (orCreateCellItemPeer != null)
                    {
                        try
                        {
                            obj = SelectorAutomationPeer.GetSupportedPropertyValueInternal(orCreateCellItemPeer, propertyId);
                        }
                        catch (Exception ex)
                        {
                            if (ex is ElementNotAvailableException)
                            {
                                goto IL_108;
                            }
                        }
                        if (value == null || obj == null)
                        {
                            if (obj == null && value == null)
                            {
                                return(base.ProviderFromPeer(orCreateCellItemPeer));
                            }
                        }
                        else if (value.Equals(obj))
                        {
                            return(base.ProviderFromPeer(orCreateCellItemPeer));
                        }
                    }
                    IL_108 :;
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            ResetChildrenCache();
            // Checks if propertyId is valid else throws ArgumentException to notify it as invalid argument is being passed
            if (propertyId != 0)
            {
                if (!SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId))
                {
                    throw new ArgumentException(SR.Get(SRID.PropertyNotSupported));
                }
            }


            IList <DataGridColumn> columns = OwningDataGrid.Columns;

            if (columns != null && columns.Count > 0)
            {
                DataGridCellItemAutomationPeer startAfterItem = null;
                if (startAfter != null)
                {
                    // get the peer corresponding to this provider
                    startAfterItem = PeerFromProvider(startAfter) as DataGridCellItemAutomationPeer;
                }

                // startIndex refers to the index of the item just after startAfterItem
                int startIndex = 0;
                if (startAfterItem != null)
                {
                    if (startAfterItem.Column == null)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.InavalidStartItem));
                    }

                    // To find the index of the item in items collection which occurs
                    // immidiately after startAfterItem.Item
                    startIndex = columns.IndexOf(startAfterItem.Column) + 1;
                    if (startIndex == 0 || startIndex == columns.Count)
                    {
                        return(null);
                    }
                }

                if (propertyId == 0 && startIndex < columns.Count)
                {
                    return(ProviderFromPeer(GetOrCreateCellItemPeer(columns[startIndex])));
                }

                DataGridCellItemAutomationPeer currentItemPeer;
                object currentValue = null;
                for (int i = startIndex; i < columns.Count; i++)
                {
                    currentItemPeer = GetOrCreateCellItemPeer(columns[i]);
                    if (currentItemPeer == null)
                    {
                        continue;
                    }
                    try
                    {
                        currentValue = SelectorAutomationPeer.GetSupportedPropertyValueInternal(currentItemPeer, propertyId);
                    }
                    catch (Exception ex)
                    {
                        if (ex is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (value == null || currentValue == null)
                    {
                        // Accept null as value corresponding to the property if it finds an item with null as the value of corresponding property else ignore.
                        if (currentValue == null && value == null)
                        {
                            return(ProviderFromPeer(currentItemPeer));
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // Match is found within the specified criterion of search
                    if (value.Equals(currentValue))
                    {
                        return(ProviderFromPeer(currentItemPeer));
                    }
                }
            }
            return(null);
        }
 internal override object GetSupportedPropertyValue(ItemAutomationPeer itemPeer, int propertyId)
 {
     return(SelectorAutomationPeer.GetSupportedPropertyValueInternal(itemPeer, propertyId));
 }