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 typeof(TabControl))
{
loop = false;
return ((ObservableTabCollection)((TabControl)parent).ItemsSource);
}
parent = parent.GetParent() as FrameworkElement;
}
return null;
}
==== EDIT ==== The Solution was this:
bool loop = true;
var parent = depObject as FrameworkElement;
while (loop)
{
if (parent != null)
{
parent = VisualTreeHelper.GetParent(parent) as FrameworkElement;
var type = parent.GetType();
if (parent.GetType() == typeof(TabControl))
{
loop = false;
return ((ObservableTabCollection)((TabControl)parent).ItemsSource);
}
}
else { loop = false; }
}
return null;