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

  • Home
  • SEARCH
  • 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 7980653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:08:25+00:00 2026-06-04T10:08:25+00:00

I have tried finding an answer to this problem and in every post I

  • 0

I have tried finding an answer to this problem and in every post I find there is an answer to finding children recursively but none of them work with hidden or collapsed children

Also in every post someone has asked if this is possible but no one has answered so I am beginning to think this isn’t possible

If anyone has a way of doing this I will be eternally grateful.

My function looks like this:

        public static DependencyObject FindLogicalDescendentByName(this DependencyObject source, string name)
    {
        DependencyObject result = null;
        IEnumerable children = LogicalTreeHelper.GetChildren(source);

        foreach (var child in children)
        {
            if (child is DependencyObject)
            {
                if (child is FrameworkElement)
                {
                    if ((child as FrameworkElement).Name.Equals(name))
                        result = (DependencyObject)child;
                    else
                        result = (child as DependencyObject).FindLogicalDescendentByName(name);
                }
                else
                {
                    result = (child as DependencyObject).FindLogicalDescendentByName(name);
                }
                if (result != null)
                    return result;
            }
        }
        return result;
    }

-EDITED
So,
I realise my problem is that I was trying to find the item before it was created,

I was binding to a property in xaml that would go off and find an item by a given name, but the item wasnt created at that point in time, if I re-ordered the item in xaml, it works and the item is found… doh!

  • 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-06-04T10:08:27+00:00Added an answer on June 4, 2026 at 10:08 am

    Here is my code, it works if you specify the X:Name and the type

    Example of the call:

    System.Windows.Controls.Image myImage = FindChild<System.Windows.Controls.Image>(this (or parent), "ImageName");
    
    
    
    /// <summary>
    /// Find specific child (name and type) from parent
    /// </summary>
    public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
    {
       // Confirm parent and childName are valid. 
       if (parent == null) return null;
    
       T foundChild = null;
    
       int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
       for (int i = 0; i < childrenCount; i++)
       {
          var child = VisualTreeHelper.GetChild(parent, i);
          // If the child is not of the request child type child
          T childType = child as T;
          if (childType == null)
          {
             // recursively drill down the tree
             foundChild = FindChild<T>(child, childName);
    
             // If the child is found, break so we do not overwrite the found child. 
             if (foundChild != null) break;
          }
          else if (!string.IsNullOrEmpty(childName))
          {
             var frameworkElement = child as FrameworkElement;
             // If the child's name is set for search
             if (frameworkElement != null && frameworkElement.Name == childName)
             {
                // if the child's name is of the request name
                foundChild = (T)child;
                break;
             }
          }
          else
          {
             // child element found.
             foundChild = (T)child;
             break;
          }
       }
    
         return foundChild;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried quite a few codes but none of them seem to work
I have tried finding a simialr example and using that to answer my problem,
I've tried finding an understandable answer to this, but given up. In order to
I have tried my best to answer this question myself through research but I
Have tried to find solutions for this and can't really come up with anything.
I have tried this but it does not work (even if I specify .wav
I have tried to find some decent documentation on traversing in jQuery, but have
I've looked around for an answer to this but I'm not finding it. I
I have searched for the answer to this and the reason I'm not finding
I have tried several things so far, but I haven't had much luck yet.

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.