Question

The actual visuals are dictated by a DataTemplate. In runtime, how can I iterate through all the visual elements of a ListBoxItem?

Was it helpful?

Solution

Assuming that you have a reference to one of the ListBoxItems in the list, you can use the VisualTreeHelper class to enumerate the visual tree of it.

Otherwise, if you have a reference to one of the items displayed in the ListBox, try calling ItemContainerGenerator.ContainerFromItem() off of the ListBox (note that the item must be displayed for this to work, since the ListBox generally only keeps items that are visible in memory).

OTHER TIPS

Keep aside the reason why you need to do so....

I think you need the VisualTreeHelper class for this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top