/// 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); }
/// 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); }
///<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); }
///<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; bool useNetFx472CompatibleAccessibilityFeatures = AccessibilitySwitches.UseNetFx472CompatibleAccessibilityFeatures; if (owner.IsGrouping) { if (itemHost == null) { return(null); } if (!useNetFx472CompatibleAccessibilityFeatures) { _reusablePeers = oldChildren; } 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); 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 (_recentlyRealizedPeers != null && _recentlyRealizedPeers.Count > 0 && this.AncestorsInvalid) { GroupItemAutomationPeer groupItemPeer = peer as GroupItemAutomationPeer; if (groupItemPeer != null) { groupItemPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(_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; } } } } } 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; if (IsVirtualized) { // 'item' is a container - get the corresponding data item DependencyObject d = item as DependencyObject; dataItem = (d != null) ? owner.ItemContainerGenerator.ItemFromContainer(d) : null; // 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. (DDVSO 781853) if (dataItem == DependencyProperty.UnsetValue) { dataItem = null; } } else { // 'item' is a data item dataItem = 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]; peer = ReusePeerForItem(peer, dataItem); 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); }
/// <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); }
/// <summary>Gets the collection of child elements of the <see cref="T:System.Windows.Controls.ItemsControl" /> that is associated with this <see cref="T:System.Windows.Automation.Peers.ItemsControlAutomationPeer" />. This method is called by <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetChildren" />.</summary> /// <returns>The collection of child elements.</returns> // Token: 0x06002733 RID: 10035 RVA: 0x000B9414 File Offset: 0x000B7614 protected override List <AutomationPeer> GetChildrenCore() { List <AutomationPeer> list = null; ItemPeersStorage <ItemAutomationPeer> dataChildren = this._dataChildren; this._dataChildren = new ItemPeersStorage <ItemAutomationPeer>(); ItemsControl itemsControl = (ItemsControl)base.Owner; ItemCollection items = itemsControl.Items; Panel itemsHost = itemsControl.ItemsHost; bool useNetFx472CompatibleAccessibilityFeatures = AccessibilitySwitches.UseNetFx472CompatibleAccessibilityFeatures; if (itemsControl.IsGrouping) { if (itemsHost == null) { return(null); } if (!useNetFx472CompatibleAccessibilityFeatures) { this._reusablePeers = dataChildren; } IList list2 = itemsHost.Children; list = new List <AutomationPeer>(list2.Count); foreach (object obj in list2) { UIElement uielement = (UIElement)obj; UIElementAutomationPeer uielementAutomationPeer = uielement.CreateAutomationPeer() as UIElementAutomationPeer; if (uielementAutomationPeer != null) { list.Add(uielementAutomationPeer); if (useNetFx472CompatibleAccessibilityFeatures) { if (this._recentlyRealizedPeers != null && this._recentlyRealizedPeers.Count > 0 && this.AncestorsInvalid) { GroupItemAutomationPeer groupItemAutomationPeer = uielementAutomationPeer as GroupItemAutomationPeer; if (groupItemAutomationPeer != null) { groupItemAutomationPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(this._recentlyRealizedPeers); } } } else if (this.AncestorsInvalid) { GroupItemAutomationPeer groupItemAutomationPeer2 = uielementAutomationPeer as GroupItemAutomationPeer; if (groupItemAutomationPeer2 != null) { groupItemAutomationPeer2.AncestorsInvalid = true; groupItemAutomationPeer2.ChildrenValid = true; } } } } return(list); } else { if (items.Count > 0) { IList list2; if (this.IsVirtualized) { if (itemsHost == null) { return(null); } list2 = itemsHost.Children; } else { list2 = items; } list = new List <AutomationPeer>(list2.Count); foreach (object obj2 in list2) { object obj3; if (this.IsVirtualized) { DependencyObject dependencyObject = obj2 as DependencyObject; obj3 = ((dependencyObject != null) ? itemsControl.ItemContainerGenerator.ItemFromContainer(dependencyObject) : null); if (obj3 == DependencyProperty.UnsetValue) { continue; } } else { obj3 = obj2; } ItemAutomationPeer itemAutomationPeer = dataChildren[obj3]; itemAutomationPeer = this.ReusePeerForItem(itemAutomationPeer, obj3); if (itemAutomationPeer == null) { itemAutomationPeer = this.CreateItemAutomationPeer(obj3); } if (itemAutomationPeer != null) { AutomationPeer wrapperPeer = itemAutomationPeer.GetWrapperPeer(); if (wrapperPeer != null) { wrapperPeer.EventsSource = itemAutomationPeer; } } if (itemAutomationPeer != null && this._dataChildren[obj3] == null) { list.Add(itemAutomationPeer); this._dataChildren[obj3] = itemAutomationPeer; } } return(list); } return(null); } }