0

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?

Max Yotos
  • 3
  • 4
  • 2
    You don't need to do all that. Use bindings for text boxes and they will be able to retrive their data (text, visibility, whatever you need) without you. – Sinatr Jan 22 '20 at 08:17
  • In my program i add TabItems dynamically and i can a few the same pages. So Is it possible to do that in my program? – Max Yotos Jan 22 '20 at 08:23
  • You can [set bindings in code](https://stackoverflow.com/a/7525254/1997232). Btw, if tab pages are the same, then why do you need tab control? – Sinatr Jan 22 '20 at 08:25
  • I have several types this pages. And user can create own combinations. – Max Yotos Jan 22 '20 at 08:27

0 Answers0