Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:55:12+00:00 2026-05-31T13:55:12+00:00

How to get all the Controls/UIElements which are nested in a Tabitem (from a

  • 0

How to get all the Controls/UIElements which are nested in a Tabitem (from a TabControl)?

I tried everything but wasn’t able to get them.

(Set the SelectedTab):

    private TabItem SelectedTab = null;
    private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        SelectedTab = (TabItem)tabControl1.SelectedItem;
    }

Now I need something like this:

  private StackPanel theStackPanelInWhichLabelsShouldBeLoaded = null;
  foreach (Control control in tabControl.Children /*doesnt exist*/, or tabControl.Items /*only TabItems*/, or /*SelectedTab.Items ??*/ ) //I Have no plan
  {
        if(control is StackPanel)
        {
            theStackPanelInWhichLabelsShouldBeLoaded = control;
            //Load Labels in the Stackpanel, thats works without problems
        }
  }

After Silvermind:
Doing this, the Count is always 1:

        UpdateLayout();
        int nChildCount = VisualTreeHelper.GetChildrenCount(SelectedTab);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:55:14+00:00Added an answer on May 31, 2026 at 1:55 pm

    TabControl has Items property (derived from ItemsControl), which returns all TabItems – http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.items.aspx. Or you can traverse visual tree:

    var firstStackPanelInTabControl = FindVisualChildren<StackPanel>(tabControl).First();
    

    Using:

    public static IEnumerable<T> FindVisualChildren<T>(DependencyObject rootObject) where T : DependencyObject
    {
      if (rootObject != null)
      {
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(rootObject); i++)
        {
          DependencyObject child = VisualTreeHelper.GetChild(rootObject, i);
    
          if (child != null && child is T)
            yield return (T)child;
    
          foreach (T childOfChild in FindVisualChildren<T>(child))
            yield return childOfChild;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a problem related to get out all the controls from some
I need to get all controls inside a specific RowDefinition/ColumnDefinition without iterating through all
I'm trying to get all controls in a winform disabled at the Load event.
I've got some code that will generically get all Controls in a form and
I try to get all WPF window controls collections. In other words i try
I want to get a collection of all label controls that are part of
How do you get two unrelated controls to raise the same custom event? All
I would need to get a Regular Expression, which matches all Unicode control characters
I want to get all the file upload controls on my page, Im adding
Is there a simple way to get all controls that contains the property .Text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.