상속: System.Windows.Automation.Peers.FrameworkElementAutomationPeer
예제 #1
0
        protected internal virtual ItemAutomationPeer FindOrCreateItemAutomationPeer(object item)
        {
            ItemAutomationPeer itemAutomationPeer = this.ItemPeers[item];

            if (itemAutomationPeer == null)
            {
                itemAutomationPeer = this.GetPeerFromWeakRefStorage(item);
            }
            if (itemAutomationPeer == null)
            {
                itemAutomationPeer = this.CreateItemAutomationPeer(item);
                if (itemAutomationPeer != null)
                {
                    itemAutomationPeer.TrySetParentInfo(this);
                }
            }
            if (itemAutomationPeer != null)
            {
                AutomationPeer wrapperPeer = itemAutomationPeer.GetWrapperPeer();
                if (wrapperPeer != null)
                {
                    wrapperPeer.EventsSource = itemAutomationPeer;
                }
            }
            return(itemAutomationPeer);
        }
예제 #2
0
        protected virtual internal ItemAutomationPeer FindOrCreateItemAutomationPeer(object item)
        {
            ItemAutomationPeer peer = ItemPeers[item];

            if (peer == null)
            {
                peer = GetPeerFromWeakRefStorage(item);
            }

            if (peer == null)
            {
                peer = CreateItemAutomationPeer(item);

                if (peer != null)
                {
                    peer.TrySetParentInfo(this);
                }
            }

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

            return(peer);
        }
        protected internal override ItemAutomationPeer FindOrCreateItemAutomationPeer(object item)
        {
            ItemAutomationPeer itemAutomationPeer = base.ItemPeers[item];
            AutomationPeer     peer = this;

            if (base.EventsSource is TreeViewDataItemAutomationPeer)
            {
                peer = (base.EventsSource as TreeViewDataItemAutomationPeer);
            }
            if (itemAutomationPeer == null)
            {
                itemAutomationPeer = base.GetPeerFromWeakRefStorage(item);
            }
            if (itemAutomationPeer == null)
            {
                itemAutomationPeer = this.CreateItemAutomationPeer(item);
                if (itemAutomationPeer != null)
                {
                    itemAutomationPeer.TrySetParentInfo(peer);
                }
            }
            if (itemAutomationPeer != null)
            {
                AutomationPeer wrapperPeer = itemAutomationPeer.GetWrapperPeer();
                if (wrapperPeer != null)
                {
                    wrapperPeer.EventsSource = itemAutomationPeer;
                }
            }
            return(itemAutomationPeer);
        }
예제 #4
0
        /// <summary>
        /// Gets the position of a MenuItem contained in a set.
        /// </summary>
        /// <remarks>
        /// If this value has already been set by the developer, that value will be used for this property. If it hasn't, we find the position ourselves.
        /// </remarks>
        /// <returns>
        /// The position of a MenuItem that is contained in a set.
        /// </returns>
        override protected int GetPositionInSetCore()
        {
            int positionInSet = base.GetPositionInSetCore();

            if (positionInSet == AutomationProperties.AutomationPositionInSetDefault)
            {
                MenuItem     owner  = (MenuItem)Owner;
                ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(owner);

                positionInSet = ItemAutomationPeer.GetPositionInSetFromItemsControl(parent, owner);

                foreach (var item in parent.Items)
                {
                    if (item == owner)
                    {
                        break;
                    }
                    if (item is Separator)
                    {
                        positionInSet -= 1;
                    }
                }
            }

            return(positionInSet);
        }
예제 #5
0
        // Token: 0x06002735 RID: 10037 RVA: 0x000B96A4 File Offset: 0x000B78A4
        internal void AddProxyToWeakRefStorage(WeakReference wr, ItemAutomationPeer itemPeer)
        {
            ItemsControl   itemsControl = base.Owner as ItemsControl;
            ItemCollection items        = itemsControl.Items;

            if (items != null && this.GetPeerFromWeakRefStorage(itemPeer.Item) == null)
            {
                this.WeakRefElementProxyStorage[itemPeer.Item] = wr;
            }
        }
예제 #6
0
        /// <summary>
        ///     Provides initialization for base class values when called by the constructor
        ///     of a derived class.
        /// </summary>
        /// <param name="item">The item to create the automation peer for.</param>
        /// <returns>The item automation peer.</returns>
        protected override ItemAutomationPeer CreateItemAutomationPeer(object item)
        {
            ItemAutomationPeer peer = null;
            var element             = item as UIElement;

            if (element != null)
            {
                peer = CreatePeerForElement(element) as ItemAutomationPeer;
            }
            return(peer);
        }
예제 #7
0
        // Token: 0x06002787 RID: 10119 RVA: 0x000BA214 File Offset: 0x000B8414
        protected override int GetPositionInSetCore()
        {
            int num = base.GetPositionInSetCore();

            if (num == -1)
            {
                MenuItem     menuItem     = (MenuItem)base.Owner;
                ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(menuItem);
                num = ItemAutomationPeer.GetPositionInSetFromItemsControl(itemsControl, menuItem);
            }
            return(num);
        }
예제 #8
0
        ///
        protected override List <AutomationPeer> GetChildrenCore()
        {
            // To avoid the situation on legacy systems which may not have new unmanaged core. with this change with old unmanaged core
            // the behavior would be same as earlier.
            if (IsVirtualized)
            {
                return(base.GetChildrenCore());
            }
            else
            {
                ItemsControl          owner    = (ItemsControl)Owner;
                ItemCollection        items    = owner.Items;
                List <AutomationPeer> children = null;
                ItemPeersStorage <ItemAutomationPeer> oldChildren = ItemPeers; //cache the old ones for possible reuse
                ItemPeers = new ItemPeersStorage <ItemAutomationPeer>();

                if (items.Count > 0)
                {
                    children = new List <AutomationPeer>(items.Count);
                    for (int i = 0; i < items.Count; i++)
                    {
                        TreeViewItem treeViewItem = owner.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
                        if (treeViewItem != null)
                        {
                            ItemAutomationPeer peer = oldChildren[items[i]];
                            if (peer == null)
                            {
                                peer = CreateItemAutomationPeer(items[i]);
                            }

                            // 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;
                                }
                            }

                            // Not to add same Item again
                            if (ItemPeers[items[i]] == null)
                            {
                                children.Add(peer);
                                ItemPeers[items[i]] = peer;
                            }
                        }
                    }
                    return(children);
                }
            }
            return(null);
        }
예제 #9
0
        // Token: 0x06002714 RID: 10004 RVA: 0x000B8D7C File Offset: 0x000B6F7C
        internal static int GetPositionInSetFromItemsControl(ItemsControl itemsControl, object item)
        {
            ItemCollection items = itemsControl.Items;
            int            num   = items.IndexOf(item);

            if (itemsControl.IsGrouping)
            {
                int num2;
                num = ItemAutomationPeer.FindPositionInGroup(items.Groups, num, out num2);
            }
            return(num + 1);
        }
예제 #10
0
        /// <summary>
        /// Gets the position of a MenuItem contained in a set.
        /// </summary>
        /// <remarks>
        /// If this value has already been set by the developer, that value will be used for this property. If it hasn't, we find the position ourselves.
        /// </remarks>
        /// <returns>
        /// The position of a MenuItem that is contained in a set.
        /// </returns>
        override protected int GetPositionInSetCore()
        {
            int positionInSet = base.GetPositionInSetCore();

            if (positionInSet == AutomationProperties.AutomationPositionInSetDefault)
            {
                MenuItem     owner  = (MenuItem)Owner;
                ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(owner);
                positionInSet = ItemAutomationPeer.GetPositionInSetFromItemsControl(parent, owner);
            }

            return(positionInSet);
        }
        // Token: 0x06002866 RID: 10342 RVA: 0x000BC534 File Offset: 0x000BA734
        internal override object GetSupportedPropertyValue(ItemAutomationPeer itemPeer, int propertyId)
        {
            if (SelectionItemPatternIdentifiers.IsSelectedProperty.Id != propertyId)
            {
                return(base.GetSupportedPropertyValue(itemPeer, propertyId));
            }
            ISelectionItemProvider selectionItemProvider = itemPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;

            if (selectionItemProvider != null)
            {
                return(selectionItemProvider.IsSelected);
            }
            return(null);
        }
예제 #12
0
        // Token: 0x06002715 RID: 10005 RVA: 0x000B8DB4 File Offset: 0x000B6FB4
        internal static int GetSizeOfSetFromItemsControl(ItemsControl itemsControl, object item)
        {
            int            result = -1;
            ItemCollection items  = itemsControl.Items;

            if (itemsControl.IsGrouping)
            {
                int position = items.IndexOf(item);
                ItemAutomationPeer.FindPositionInGroup(items.Groups, position, out result);
            }
            else
            {
                result = items.Count;
            }
            return(result);
        }
예제 #13
0
 // Token: 0x06002734 RID: 10036 RVA: 0x000B9678 File Offset: 0x000B7878
 internal ItemAutomationPeer ReusePeerForItem(ItemAutomationPeer peer, object item)
 {
     if (peer == null)
     {
         peer = this.GetPeerFromWeakRefStorage(item);
         if (peer != null)
         {
             peer.AncestorsInvalid = false;
             peer.ChildrenValid    = false;
         }
     }
     if (peer != null)
     {
         peer.ReuseForItem(item);
     }
     return(peer);
 }
예제 #14
0
        // Token: 0x06002713 RID: 10003 RVA: 0x000B8D30 File Offset: 0x000B6F30
        protected override int GetSizeOfSetCore()
        {
            AutomationPeer wrapperPeer = this.GetWrapperPeer();

            if (wrapperPeer != null)
            {
                int num = wrapperPeer.GetSizeOfSet();
                if (num == -1)
                {
                    ItemsControl itemsControl = (ItemsControl)this.ItemsControlAutomationPeer.Owner;
                    num = ItemAutomationPeer.GetSizeOfSetFromItemsControl(itemsControl, this.Item);
                }
                return(num);
            }
            this.ThrowElementNotAvailableException();
            return(-1);
        }
        /// <summary>
        /// Retrieves a UI automation provider for each child element that is
        /// selected.
        /// </summary>
        /// <returns>An array of UI automation providers.</returns>
        IRawElementProviderSimple[] ISelectionProvider.GetSelection()
        {
            TabControl tabControl = Owner as TabControl;

            if (tabControl.SelectedItem == null)
            {
                return(null);
            }
            List <IRawElementProviderSimple> list = new List <IRawElementProviderSimple>(1);

            ItemAutomationPeer peer = CreateItemAutomationPeer(tabControl.SelectedItem);

            if (peer != null)
            {
                list.Add(ProviderFromPeer(peer));
            }
            return(list.ToArray());
        }
        // This method is called from DataGrid.OnSelectionChanged
        // Raises the selection events when Items selection changes
        internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e)
        {
            int numSelected = this.OwningDataGrid.SelectedItems.Count;
            int numAdded    = e.AddedItems.Count;

            // If the result of an AddToSelection or RemoveFromSelection is a single selected item,
            // then all we raise is the ElementSelectedEvent for single item
            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) &&
                numSelected == 1 && numAdded == 1)
            {
                ItemAutomationPeer peer = FindOrCreateItemAutomationPeer(this.OwningDataGrid.SelectedItem);
                if (peer != null)
                {
                    peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                }
            }
            else
            {
                int i;
                if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection))
                {
                    for (i = 0; i < e.AddedItems.Count; i++)
                    {
                        ItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.AddedItems[i]);
                        if (peer != null)
                        {
                            peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
                        }
                    }
                }

                if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
                {
                    for (i = 0; i < e.RemovedItems.Count; i++)
                    {
                        ItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.RemovedItems[i]);
                        if (peer != null)
                        {
                            peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
                        }
                    }
                }
            }
        }
        /// <summary>Gets the collection of child elements of the <see cref="T:System.Windows.ContentElement" /> that is associated with this <see cref="T:System.Windows.Automation.Peers.ContentElementAutomationPeer" />. Called by <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetChildren" />.</summary>
        /// <returns>A collection of <see cref="T:System.Windows.Automation.Peers.TreeViewItemAutomationPeer" /> elements, or <see langword="null" /> if the <see cref="T:System.Windows.Controls.TreeView" /> that is associated with this <see cref="T:System.Windows.Automation.Peers.TreeViewAutomationPeer" /> is empty.</returns>
        // Token: 0x06002863 RID: 10339 RVA: 0x000BC40C File Offset: 0x000BA60C
        protected override List <AutomationPeer> GetChildrenCore()
        {
            if (this.IsVirtualized)
            {
                return(base.GetChildrenCore());
            }
            ItemsControl   itemsControl = (ItemsControl)base.Owner;
            ItemCollection items        = itemsControl.Items;
            ItemPeersStorage <ItemAutomationPeer> itemPeers = base.ItemPeers;

            base.ItemPeers = new ItemPeersStorage <ItemAutomationPeer>();
            if (items.Count > 0)
            {
                List <AutomationPeer> list = new List <AutomationPeer>(items.Count);
                for (int i = 0; i < items.Count; i++)
                {
                    TreeViewItem treeViewItem = itemsControl.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
                    if (treeViewItem != null)
                    {
                        ItemAutomationPeer itemAutomationPeer = itemPeers[items[i]];
                        if (itemAutomationPeer == null)
                        {
                            itemAutomationPeer = this.CreateItemAutomationPeer(items[i]);
                        }
                        if (itemAutomationPeer != null)
                        {
                            AutomationPeer wrapperPeer = itemAutomationPeer.GetWrapperPeer();
                            if (wrapperPeer != null)
                            {
                                wrapperPeer.EventsSource = itemAutomationPeer;
                            }
                        }
                        if (base.ItemPeers[items[i]] == null)
                        {
                            list.Add(itemAutomationPeer);
                            base.ItemPeers[items[i]] = itemAutomationPeer;
                        }
                    }
                }
                return(list);
            }
            return(null);
        }
        internal ItemAutomationPeer ReusePeerForItem(ItemAutomationPeer peer, object item)
        {
            if (peer == null)
            {
                peer = GetPeerFromWeakRefStorage(item);
                if (peer != null)
                {
                    // As cached peer is getting used it must be invalidated.
                    peer.AncestorsInvalid = false;
                    peer.ChildrenValid    = false;
                }
            }

            if (peer != null)
            {
                peer.ReuseForItem(item);
            }

            return(peer);
        }
        // Token: 0x0600257B RID: 9595 RVA: 0x000B44A0 File Offset: 0x000B26A0
        internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e)
        {
            int count  = this.OwningDataGrid.SelectedItems.Count;
            int count2 = e.AddedItems.Count;

            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && count == 1 && count2 == 1)
            {
                ItemAutomationPeer itemAutomationPeer = this.FindOrCreateItemAutomationPeer(this.OwningDataGrid.SelectedItem);
                if (itemAutomationPeer != null)
                {
                    itemAutomationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                    return;
                }
            }
            else
            {
                if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection))
                {
                    for (int i = 0; i < e.AddedItems.Count; i++)
                    {
                        ItemAutomationPeer itemAutomationPeer2 = this.FindOrCreateItemAutomationPeer(e.AddedItems[i]);
                        if (itemAutomationPeer2 != null)
                        {
                            itemAutomationPeer2.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
                        }
                    }
                }
                if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
                {
                    for (int i = 0; i < e.RemovedItems.Count; i++)
                    {
                        ItemAutomationPeer itemAutomationPeer3 = this.FindOrCreateItemAutomationPeer(e.RemovedItems[i]);
                        if (itemAutomationPeer3 != null)
                        {
                            itemAutomationPeer3.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
                        }
                    }
                }
            }
        }
        // Token: 0x060026EA RID: 9962 RVA: 0x000B87EC File Offset: 0x000B69EC
        internal void InvalidateGroupItemPeersContainingRecentlyRealizedPeers(List <ItemAutomationPeer> recentlyRealizedPeers)
        {
            ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(base.Owner);

            if (itemsControl != null)
            {
                CollectionViewGroupInternal collectionViewGroupInternal = itemsControl.ItemContainerGenerator.ItemFromContainer(base.Owner) as CollectionViewGroupInternal;
                if (collectionViewGroupInternal != null)
                {
                    for (int i = 0; i < recentlyRealizedPeers.Count; i++)
                    {
                        ItemAutomationPeer itemAutomationPeer = recentlyRealizedPeers[i];
                        object             item = itemAutomationPeer.Item;
                        if (collectionViewGroupInternal.LeafIndexOf(item) >= 0)
                        {
                            this.AncestorsInvalid = true;
                            base.ChildrenValid    = true;
                        }
                    }
                }
            }
        }
예제 #21
0
        /// <summary>
        /// Gets the size of a set that contains this MenuItem.
        /// </summary>
        /// <remarks>
        /// If <see cref="AutomationProperties.PositionInSetProperty"/> hasn't been set
        /// this method will calculate the position of the MenuItem based on its parent ItemsControl,
        /// if the ItemsControl is grouping the position will be relative to the group containing this item.
        /// </remarks>
        /// <returns>
        /// The value of <see cref="AutomationProperties.PositionInSetProperty"/> if it has been set, or it's position relative to the parent ItemsControl or GroupItem.
        /// </returns>
        override protected int GetSizeOfSetCore()
        {
            int sizeOfSet = base.GetSizeOfSetCore();

            if (sizeOfSet == AutomationProperties.AutomationSizeOfSetDefault)
            {
                MenuItem     owner  = (MenuItem)Owner;
                ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(owner);

                sizeOfSet = ItemAutomationPeer.GetSizeOfSetFromItemsControl(parent, owner);

                foreach (var item in parent.Items)
                {
                    if (item is Separator)
                    {
                        sizeOfSet -= 1;
                    }
                }
            }

            return(sizeOfSet);
        }
예제 #22
0
        // Token: 0x06002740 RID: 10048 RVA: 0x000B9990 File Offset: 0x000B7B90
        internal ItemAutomationPeer GetPeerFromWeakRefStorage(object item)
        {
            ItemAutomationPeer itemAutomationPeer = null;
            WeakReference      weakReference      = this.WeakRefElementProxyStorage[item];

            if (weakReference != null)
            {
                ElementProxy elementProxy = weakReference.Target as ElementProxy;
                if (elementProxy != null)
                {
                    itemAutomationPeer = (base.PeerFromProvider(elementProxy) as ItemAutomationPeer);
                    if (itemAutomationPeer == null)
                    {
                        this.WeakRefElementProxyStorage.Remove(item);
                    }
                }
                else
                {
                    this.WeakRefElementProxyStorage.Remove(item);
                }
            }
            return(itemAutomationPeer);
        }
예제 #23
0
        // Provides Peer if exist in Weak Reference Storage
        internal ItemAutomationPeer GetPeerFromWeakRefStorage(object item)
        {
            ItemAutomationPeer returnPeer = null;
            WeakReference      weakRefEP  = WeakRefElementProxyStorage[item];

            if (weakRefEP != null)
            {
                ElementProxy provider = weakRefEP.Target as ElementProxy;
                if (provider != null)
                {
                    returnPeer = PeerFromProvider(provider as IRawElementProviderSimple) as ItemAutomationPeer;
                    if (returnPeer == null)
                    {
                        WeakRefElementProxyStorage.Remove(item);
                    }
                }
                else
                {
                    WeakRefElementProxyStorage.Remove(item);
                }
            }

            return(returnPeer);
        }
예제 #24
0
        /// <summary>
        /// It returns the ItemAutomationPeer if it exist corresponding to the item otherwise it creates
        /// one and does add the Handle and parent info by calling TrySetParentInfo.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override internal ItemAutomationPeer FindOrCreateItemAutomationPeer(object item)
        {
            ItemAutomationPeer peer       = ItemPeers[item];
            AutomationPeer     parentPeer = this;

            if (EventsSource as TreeViewDataItemAutomationPeer != null)
            {
                parentPeer = EventsSource as TreeViewDataItemAutomationPeer;
            }

            if (peer == null)
            {
                peer = GetPeerFromWeakRefStorage(item);
            }

            if (peer == null)
            {
                peer = CreateItemAutomationPeer(item);

                if (peer != null)
                {
                    peer.TrySetParentInfo(parentPeer);
                }
            }

            if (peer != null)
            {
                AutomationPeer wrapperPeer = (peer as ItemAutomationPeer).GetWrapperPeer();
                if (wrapperPeer != null)
                {
                    wrapperPeer.EventsSource = peer;
                }
            }

            return(peer);
        }
예제 #25
0
        // To purge the collection corresponding to WeakReference for dead references
        //
        public void PurgeWeakRefCollection()
        {
            if (!(typeof(T).IsAssignableFrom(typeof(System.WeakReference))))
            {
                return;
            }
            List <object> cleanUpItemsCollection = new List <object>();

            if (_usesHashCode)
            {
                if (_hashtable == null)
                {
                    return;
                }
                foreach (DictionaryEntry dictionaryEntry in _hashtable)
                {
                    WeakReference weakRef = dictionaryEntry.Value as WeakReference;
                    if (weakRef == null)
                    {
                        cleanUpItemsCollection.Add(dictionaryEntry.Key);
                        continue;
                    }
                    ElementProxy proxy = weakRef.Target as ElementProxy;
                    if (proxy == null)
                    {
                        cleanUpItemsCollection.Add(dictionaryEntry.Key);
                        continue;
                    }
                    ItemAutomationPeer peer = proxy.Peer as ItemAutomationPeer;
                    if (peer == null)
                    {
                        cleanUpItemsCollection.Add(dictionaryEntry.Key);
                    }
                }
            }

            else
            {
                if (_list == null)
                {
                    return;
                }
                foreach (KeyValuePair <object, T> keyValuePair in _list)
                {
                    WeakReference weakRef = keyValuePair.Value as WeakReference;
                    if (weakRef == null)
                    {
                        cleanUpItemsCollection.Add(keyValuePair.Key);
                        continue;
                    }
                    ElementProxy proxy = weakRef.Target as ElementProxy;
                    if (proxy == null)
                    {
                        cleanUpItemsCollection.Add(keyValuePair.Key);
                        continue;
                    }
                    ItemAutomationPeer peer = proxy.Peer as ItemAutomationPeer;
                    if (peer == null)
                    {
                        cleanUpItemsCollection.Add(keyValuePair.Key);
                    }
                }
            }

            foreach (object item in cleanUpItemsCollection)
            {
                Remove(item);
            }
        }
 internal override object GetSupportedPropertyValue(ItemAutomationPeer itemPeer, int propertyId)
 {
     return SelectorAutomationPeer.GetSupportedPropertyValueInternal(itemPeer, propertyId);
 }
        ///
        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>
 /// Support for IsSelectedProperty should come from SelectorAutomationPeer only, 
 /// </summary> 
 internal override object GetSupportedPropertyValue(ItemAutomationPeer itemPeer, int propertyId)
 { 
     if (SelectionItemPatternIdentifiers.IsSelectedProperty.Id == propertyId)
     {
         ISelectionItemProvider selectionItem = itemPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;
         if (selectionItem != null) 
             return selectionItem.IsSelected;
         else 
             return null; 
     }
     return base.GetSupportedPropertyValue(itemPeer, propertyId); 
 }
예제 #29
0
        ///<summary>
        /// If grouping is enabled then return peers corresponding to all the items in container
        /// otherwise sees VirtualizingStackPanel(itemsHost) and return peers corresponding to
        /// items which are de-virtualized.
        ///</summary>
        protected override List <AutomationPeer> GetChildrenCore()
        {
            List <AutomationPeer> children = null;
            ItemPeersStorage <ItemAutomationPeer> oldChildren = _dataChildren; //cache the old ones for possible reuse

            _dataChildren = new ItemPeersStorage <ItemAutomationPeer>();
            ItemsControl   owner      = (ItemsControl)Owner;
            ItemCollection items      = owner.Items;
            Panel          itemHost   = owner.ItemsHost;
            IList          childItems = null;

            if (owner.IsGrouping)
            {
                if (itemHost == null)
                {
                    return(null);
                }

                childItems = itemHost.Children;
                children   = new List <AutomationPeer>(childItems.Count);

                foreach (UIElement child in childItems)
                {
                    UIElementAutomationPeer peer = child.CreateAutomationPeer() as UIElementAutomationPeer;
                    if (peer != null)
                    {
                        children.Add(peer);

                        //
                        // 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 (_recentlyRealizedPeers != null && _recentlyRealizedPeers.Count > 0 && this.AncestorsInvalid)
                        {
                            GroupItemAutomationPeer groupItemPeer = peer as GroupItemAutomationPeer;
                            if (groupItemPeer != null)
                            {
                                groupItemPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(_recentlyRealizedPeers);
                            }
                        }
                    }
                }

                return(children);
            }
            else if (items.Count > 0)
            {
                // To avoid the situation on legacy systems which may not have new unmanaged core. this check with old unmanaged core
                // ensures the older behavior as ItemContainer pattern won't be available.
                if (IsVirtualized)
                {
                    if (itemHost == null)
                    {
                        return(null);
                    }

                    childItems = itemHost.Children;
                }
                else
                {
                    childItems = items;
                }
                children = new List <AutomationPeer>(childItems.Count);

                foreach (object item in childItems)
                {
                    object dataItem = ((IsVirtualized && ((MS.Internal.Controls.IGeneratorHost)owner).IsItemItsOwnContainer(item)) ? owner.GetItemOrContainerFromContainer(item as UIElement) : item);

                    // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client
                    ItemAutomationPeer peer = oldChildren[dataItem];
                    if (peer == null)
                    {
                        peer = 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 = 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.GetWrapperPeer();
                        if (wrapperPeer != null)
                        {
                            wrapperPeer.EventsSource = peer;
                        }
                    }

                    // protection from indistinguishable items - for example, 2 strings with same value
                    // this scenario does not work in ItemsControl however is not checked for.
                    if (_dataChildren[dataItem] == null)
                    {
                        children.Add(peer);
                        _dataChildren[dataItem] = peer;
                    }
                }

                return(children);
            }

            return(null);
        }
        // Token: 0x060025DC RID: 9692 RVA: 0x000B53C8 File Offset: 0x000B35C8
        protected override List <AutomationPeer> GetChildrenCore()
        {
            List <AutomationPeer> list = null;
            ItemPeersStorage <ItemAutomationPeer> itemPeers = base.ItemPeers;

            base.ItemPeers = new ItemPeersStorage <ItemAutomationPeer>();
            ItemsControl itemsControl   = (ItemsControl)base.Owner;
            DataGrid     owningDataGrid = this.OwningDataGrid;

            if (owningDataGrid != null && owningDataGrid.Columns.Count > 0)
            {
                Panel itemsHost = itemsControl.ItemsHost;
                IList list2;
                if (this.IsVirtualized)
                {
                    if (itemsHost == null)
                    {
                        return(null);
                    }
                    list2 = itemsHost.Children;
                }
                else
                {
                    list2 = this.OwningDataGrid.Columns;
                }
                list = new List <AutomationPeer>(list2.Count);
                foreach (object obj in list2)
                {
                    DataGridColumn dataGridColumn;
                    if (obj is DataGridColumnHeader)
                    {
                        dataGridColumn = ((DataGridColumnHeader)obj).Column;
                    }
                    else
                    {
                        dataGridColumn = (obj as DataGridColumn);
                    }
                    ItemAutomationPeer itemAutomationPeer = itemPeers[dataGridColumn];
                    if (itemAutomationPeer == null)
                    {
                        itemAutomationPeer = base.GetPeerFromWeakRefStorage(dataGridColumn);
                        if (itemAutomationPeer != null)
                        {
                            itemAutomationPeer.AncestorsInvalid = false;
                            itemAutomationPeer.ChildrenValid    = false;
                        }
                    }
                    object o = (dataGridColumn == null) ? null : dataGridColumn.Header;
                    if (itemAutomationPeer == null || !ItemsControl.EqualsEx(itemAutomationPeer.Item, o))
                    {
                        itemAutomationPeer = this.CreateItemAutomationPeer(dataGridColumn);
                    }
                    if (itemAutomationPeer != null)
                    {
                        AutomationPeer wrapperPeer = itemAutomationPeer.GetWrapperPeer();
                        if (wrapperPeer != null)
                        {
                            wrapperPeer.EventsSource = itemAutomationPeer;
                        }
                    }
                    if (itemAutomationPeer != null && base.ItemPeers[dataGridColumn] == null)
                    {
                        list.Add(itemAutomationPeer);
                        base.ItemPeers[dataGridColumn] = itemAutomationPeer;
                    }
                }
                return(list);
            }
            return(null);
        }
        /// <summary>Retrieves an element with 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: 0x060025DD RID: 9693 RVA: 0x000B555C File Offset: 0x000B375C
        IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            base.ResetChildrenCache();
            if (propertyId != 0 && !this.IsPropertySupportedByControlForFindItem(propertyId))
            {
                throw new ArgumentException(SR.Get("PropertyNotSupported"));
            }
            ItemsControl itemsControl = (ItemsControl)base.Owner;
            IList        list         = null;

            if (itemsControl != null)
            {
                list = this.OwningDataGrid.Columns;
            }
            if (list != null && list.Count > 0)
            {
                DataGridColumnHeaderItemAutomationPeer dataGridColumnHeaderItemAutomationPeer = null;
                if (startAfter != null)
                {
                    dataGridColumnHeaderItemAutomationPeer = (base.PeerFromProvider(startAfter) as DataGridColumnHeaderItemAutomationPeer);
                    if (dataGridColumnHeaderItemAutomationPeer == null)
                    {
                        return(null);
                    }
                }
                int num = 0;
                if (dataGridColumnHeaderItemAutomationPeer != null)
                {
                    if (dataGridColumnHeaderItemAutomationPeer.Item == null)
                    {
                        throw new InvalidOperationException(SR.Get("InavalidStartItem"));
                    }
                    num = list.IndexOf(dataGridColumnHeaderItemAutomationPeer.Column) + 1;
                    if (num == 0 || num == list.Count)
                    {
                        return(null);
                    }
                }
                if (propertyId == 0)
                {
                    for (int i = num; i < list.Count; i++)
                    {
                        if (list.IndexOf(list[i]) == i)
                        {
                            return(base.ProviderFromPeer(this.FindOrCreateItemAutomationPeer(list[i])));
                        }
                    }
                }
                object obj = null;
                for (int j = num; j < list.Count; j++)
                {
                    ItemAutomationPeer itemAutomationPeer = this.FindOrCreateItemAutomationPeer(list[j]);
                    if (itemAutomationPeer != null)
                    {
                        try
                        {
                            obj = this.GetSupportedPropertyValue(itemAutomationPeer, propertyId);
                        }
                        catch (Exception ex)
                        {
                            if (ex is ElementNotAvailableException)
                            {
                                goto IL_16B;
                            }
                        }
                        if (value == null || obj == null)
                        {
                            if (obj == null && value == null && list.IndexOf(list[j]) == j)
                            {
                                return(base.ProviderFromPeer(itemAutomationPeer));
                            }
                        }
                        else if (value.Equals(obj) && list.IndexOf(list[j]) == j)
                        {
                            return(base.ProviderFromPeer(itemAutomationPeer));
                        }
                    }
                    IL_16B :;
                }
            }
            return(null);
        }
        ///
        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)
                {
                    Panel itemsHost = owner.ItemsHost;

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

                    IList childItems = itemsHost.Children;
                    List <AutomationPeer> children = new List <AutomationPeer>(childItems.Count);

                    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);

                                //
                                // 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
                        {
                            object item = itemsControl.GetItemOrContainerFromContainer(child);

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

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

                            if (peer != null)
                            {
                                //
                                // 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.
                            if (itemsControlAP.ItemPeers[item] == null)
                            {
                                children.Add(peer);
                                itemsControlAP.ItemPeers[item] = peer;
                            }
                        }
                    }

                    return(children);
                }
            }

            return(null);
        }