views:

22

answers:

1

Considering an already loaded and rendered TabControl with three tabs, with selected tab being index 1 (the middle one):

Tab 1: Has one TextBox

Tab 2: Has two TextBoxes

Tab 3: Has three TextBoxes

If I iterate through the selectedItem's visual tree with VisualTreeHelper, I will get Two textBoxes within the TabControl's children.

I want to iterate again when the tab selection changes and access the new tab's controls. If I switch to tab index 2, I should find three textboxes using VisualTreeHelper.

The normal solution would be to subscribe to the selection changed event and go through the tree to fetch the newly shown controls. The problem is that at this moment in time, the visual tree still has the old tab, making this search worthless.

How can I intercept the moment when the new TabItem is shown and trigger my search?

I'm creating a dynamic validation engine that monitors all input controls of a given UI, even when it changes either by ContentControl template changes or TabControl selected tab changes... I hope you get the picture.

Any ideas?

A: 

The TabControl loads/unloads its items when you switch tabs, so you should be able to attach your validation on the TabItem's Loaded event.

Rachel