Hello,
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!