I have a requirement get access to particular visual elements in any given view. This is easy on statically declared items in xaml since they are available anytime. However, datatemplated ItemsControls generate their visual tree at runtime. For example, a TabControl
bound to a Collection of child ViewModels.
I need access to views once they are created by the ItemContainerGenerator
. I tried hooking up to the StatusChanged
event on the ItemContainerGenerator
and it successfully fires, and I can successfully get hold of (in the case of a TabControl
) the TabItem
container. However, when I use the VisualTreeHelper
to get it's children, it's empty.
Is there any reason why the visual tree of the TabItem
is empty? Is there a another event I should be hooking onto to achieve this?