adding tabs to tabcontrol from inside usercontrol

Posted by Jakob on Stack Overflow See other posts from Stack Overflow or by Jakob
Published on 2010-06-17T18:14:13Z Indexed on 2010/06/17 21:53 UTC
Read the original article Hit count: 426

Filed under:
|
|
|

How can I add tabs to a tabcontrol that exists in one usercontrol from another usercontrol that is contained within a tab itself?? Can I do it without passing in the tabcontrol as a parameter in the constructor, perhaps via some static global method?

I've tried

public static ObservableTabCollection FindCollectionFromUC(this DependencyObject depObject)
        {
            bool loop = true;
            var parent = (VisualTreeHelper.GetParent(depObject) as FrameworkElement);
            while (loop)
            {
                if (parent.GetType() is TabControl)
                {
                    loop = false;
                    return ((ObservableTabCollection)((TabControl)parent).ItemsSource);
                }
            }
            return null;
        }

but this is just an infinite loop

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf