tags:

views:

29

answers:

1

Am using the below function to get the topmost parent in my application.

private DependencyObject GetTopParent()
    {
        DependencyObject dpParent = this.Parent;
        do
        {
            dpParent = LogicalTreeHelper.GetParent(dpParent);
        } while (dpParent.GetType().BaseType != typeof(Window));
        return dpParent as DependencyObject;
    }

How to get all the UI Element or children into a stackpanel??? Like

StackPanel parentControl = this.Parent as StackPanel;
A: 

StackPanel inherits from the Panel class, which exposes a property called Children.

In other words you should have no problem accessing :

parentControl.Children

Does this help?

Maciek