I have TabControl. I am tring to use:
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject rootObject) where T : DependencyObject
{
if (rootObject != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(rootObject); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(rootObject, i);
if (child != null && child is T)
yield return (T)child;
foreach (T childOfChild in FindVisualChildren<T>(child))
yield return childOfChild;
}
}
}
to find all textboxes from selected TabItem.
I do it because i have list with text for every TextBoxes in TabItem. When i change TabItem i want to save change for last TabItem and reload text for selected TabItem.
I tried use SelectionChanged in TabControl, but it dont work good, and FindVisualChildren dont return any textboxes. It's look like it wasnt initialize. If i run this in Task with dealey nothing changes.
This metod work without problem when is assigned to a separate button. But I would like it to happen automatically.
Xaml show me is there event <EventSetter Event="Initialized" Handler="TabItem_Initialized"/>
but it throw The event Initialized is not a RoutedEvent.
How can i detect TabItem will be changed before, and new tab item is initialized?