title: Silverlight 3 - Find Element inside items control
body: <p>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:</p>
  
  <pre><code>&lt;ItemsControl x:Name="myItemsControl"&gt;
    &lt;ItemsControl.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;controls:TreeView x:Name="myTreeView"&gt;
        &lt;/controls:TreeView&gt;
      &lt;/DataTemplate&gt;                                     
    &lt;/ItemsControl.ItemTemplate&gt;                                        
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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  
    }
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>Thank you!</p>