protected override List <AutomationPeer> GetChildrenCore() { // Call the base in case we have children in the header var headerChildren = base.GetChildrenCore(); // Only if the TabItem is selected we need to add its visual children if (!(GetWrapper() is TabItem tabItem) || tabItem.IsSelected == false) { return(headerChildren); } if (!(ItemsControlAutomationPeer.Owner is TabControlEx parentTabControl)) { return(headerChildren); } var contentHost = parentTabControl.FindChildContentPresenter(tabItem.Content, tabItem); if (contentHost is not null) { var contentHostPeer = new FrameworkElementAutomationPeer(contentHost); var contentChildren = contentHostPeer.GetChildren(); if (contentChildren is not null) { if (headerChildren is null) { headerChildren = contentChildren; } else { headerChildren.AddRange(contentChildren); } } } return(headerChildren); }
/// <inheritdoc /> protected override List <AutomationPeer> GetChildrenCore() { var children = GetHeaderChildren() ?? new List <AutomationPeer>(); if (this.OwningBackstageTabItem.IsSelected == false) { return(children); } if (this.OwningBackstageTabItem.TabControlParent?.SelectedContentHost != null) { var contentHostPeer = new FrameworkElementAutomationPeer(this.OwningBackstageTabItem.TabControlParent.SelectedContentHost); var contentChildren = contentHostPeer.GetChildren(); if (contentChildren != null) { children.AddRange(contentChildren); } } return(children); List <AutomationPeer> GetHeaderChildren() { if (this.OwningBackstageTabItem.Header is string) { return(null); } if (this.OwningBackstageTabItem.HeaderContentHost != null) { return(new FrameworkElementAutomationPeer(this.OwningBackstageTabItem.HeaderContentHost).GetChildren()); } return(null); } }