简体   繁体   中英

How do I get the Chart Series' Parent's Parent's Parent's detail?

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

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM