navigate all items in a wpf tree view
Posted
by
Brian Leahy
on Stack Overflow
See other posts from Stack Overflow
or by Brian Leahy
Published on 2009-04-03T21:57:44Z
Indexed on
2012/09/21
9:38 UTC
Read the original article
Hit count: 263
I want to be able to traverse the visual ui tree looking for an element with an ID bound to the visual element's Tag property.
I'm wondering how i do this. Controls don't have children to traverse.
I started using LogicalTreeHelper.GetChildren, which seems to work as intended, up until i hit a TreeView control... then LogicalTreeHelper.GetChildren doesnt return any children.
Note: the purpose is to find the visual UI element that corresponds to the data item. That is, given an ID of the item, Go find the UI element displaying it.
Edit: I am apparently am not explaining this well enough. I am binding some data objects to a TreeView control and then wanting to select a specific item programaticly given that business object's ID. I dont see why it's so hard to travers the visual tree and find the element i want, as the data object's ID is in the Tag property of the appropriate visual element. I'm using Mole and I am able to find the UI element with the appropriate ID in it's Tag. I just cannot find the visual element in code. LogicalTreeHelper does not traverse any items in the tree. Neither does ItemContainerGenerator.ContainerFromItem retrieve anything for items in the tree view.
© Stack Overflow or respective owner