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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:47:40+00:00 2026-05-14T04:47:40+00:00

I have an ItemsControl that is bound to a collection of objects. Each object

  • 0

I have an ItemsControl that is bound to a collection of objects. Each object has it’s own collection as well as other vital properties. To display the objects within an object, I’m displaying a TreeView inside of a ItemsControl. I know this sounds crazy. But, this is just a trimmed down version of what I am trying to accomplish to keep the question focused on the problem. Here is my sample:

<ItemsControl x:Name="myItemsControl">
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <controls:TreeView x:Name="myTreeView">
      </controls:TreeView>
    </DataTemplate>                                     
  </ItemsControl.ItemTemplate>                                        
</ItemsControl>

When a user clicks a button, I need to retrieve the current TreeView associated with a specific object. In an attempt to do this, I am trying the following:

MyClass instanceToFind = (MyClass)(IdentifyDesiredInstance());                
foreach (MyClass instance in myItemsControl.Items)
{
  if (instance.ID == instanceToFind.ID)
  {
     TreeView treeView = null; // How do I get the TreeView?

     // Do other necessary updates  
  }
}

The code snippet above shows where I am trying to get the TreeView. How do I get the TreeView when looping through the items in an itemscontrol?

Thank you!

  • 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-14T04:47:40+00:00Added an answer on May 14, 2026 at 4:47 am

    You need to use the VisualTreeHelper.GetChild and VisualTreeHelper.GetChildrenCount methods to iterate through the view’s children until you find the tree that corresponds to your item. You should be able to check the TreeView.DataContext property against your item to verify its the right one. Note, you need to use this recursively as GetChild only retrieves immediate children.

    As you’d need to iterate the visual tree anyway, I recommend abandoning your current loop and instead, just looping the children, checking the ID of their data contexts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ItemsControl that is bound to collection of type Student. Inside the ItemTemplate
I have an items control that is bound to a collection of objects. The
I have an ItemsControl that is bound to a list of Objects. I have
I have a ItemsControl that's bound to an object, within the datatemplate of the
I have a WPF ItemsControl that is bound to an ObservableCollection. The XAML: <ItemsControl
I have an ItemsControl with a DataTemplate that has been defined. My ItemsControl definition
I have a TreeView that is bound to a collection class that I have
I have a xaml page that has an ItemsControl control on it. ItemsControl is
I have a bound treeview with an ItemsControl that dynamically creates the treeview items
I wrote some controler that have itemsControl. Each item in the control is some

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.