views:

51

answers:

1

Hi All,

I am having some difficulties of getting the ancestor of a chart series on silverlight.

I can get the parent, but it is a type of Primitive, and then I can get to the parent of that parent by specifying the type, however, I am not sure how many level deep can that be when it reaches to the Chart, and I would like to get to the Chart.

Can someone guide me to do that in code without specifying the type of the parent.

Thanks

A: 

I might have a suggestion...

I haven't tried it but what about searching by the Name property on a FrameworkElement?

public static FrameworkElement FindAncestorByName(FrameworkElement element, string name)
{
    while (element != null)
    {
     if (element.Name == name)
      return element;

     DependencyObject obj = VisualTreeHelper.GetParent(element);
     element = obj as FrameworkElement;
    }
    return null;
}

This could return nothing when there is a DependencyObject in the VisualTree which is not a FrameworkElement. But I think this is worth a shot...

Zenuka