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 521307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:14:12+00:00 2026-05-13T08:14:12+00:00

In a window of my WPF application I have a number of objects which

  • 0

In a window of my WPF application I have a number of objects which dirived from a custom control:

...
<MyNamespace:MyCustControl x:Name="x4y3" />
<MyNamespace:MyCustControl x:Name="x4y4" />
<MyNamespace:MyCustControl x:Name="x4y5" />
<MyNamespace:MyCustControl x:Name="x4y6" />
<MyNamespace:MyCustControl x:Name="x4y7" />
...

In my code I can easily reference each of them individually by name:

x1y1.IsSelected = true;

How, in my code, could I iterate through whole set of them in loop?

foreach (... in ???)
{
 ....

}
  • 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-13T08:14:12+00:00Added an answer on May 13, 2026 at 8:14 am

    You can use VisualTreeHelper or LogicalTreeHelper to scan all the content of your Window or Page and locate the specific controls (maybe by checking if their type is MyCustControl

    private IEnumerable<MyCustControl> FindMyCustControl(DependencyObject root)
    {
        int count = VisualTreeHelper.GetChildrenCount(root);
        for (int i = 0; i < count; ++i)
        {
            DependencyObject child = VisualTreeHelper.GetChild(root, i);
            if (child is MyCustControl)
            {
                yield return (MyCustControl)child;
            }
            else
            {
                foreach (MyCustControl found in FindMyCustControl(child))
                {
                    yield return found;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have window form in my WPF Application when I open new window from
I created a wpf application which have a single window which is getting started
I have a WPF application which launches a WPF window. In the window, I
I have a wpf application. In the window i have a TextBlock which contains
I have a WPF application that uses a custom window frame. My problem is
In WPF application I have MainWindow : Window which loads a POSView : UserControl
I have a WPF application (.exe) which needs to open and display a window
I am developing a WPF application, and have created a custom control, we will
I have a WPF Windows application. In one window there is a particular stackpanel
I have a C# application using WPF consisting of a single Window holding four

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.