System.Windows.Media
namespace has the
VisualTreeHelper
class that you can use to traverse the dependancy tree using
GetChild
and
GetParent
methods.
So you could do something like this (untested):
private FrameworkElement GetParent(FrameworkElement item, Type targetType)
{
var parent = VisualTreeHelper.GetParent(item);
while (parent.GetType() != targetType)
{
parent = VisualTreeHelper.GetParent(parent);
}
return parent;
}
Then to use would be (untested):
var tabItem = GetParent(sender as FrameworkElement, TabItem);