[ACCEPTED]-WPF Get UserControl owner (the container element)-user-controls

Accepted answer
Score: 20

I came up with this solution, but post if 1 you have a better one. Thanks!

DependencyObject ucParent = this.Parent;

while (!(ucParent is UserControl))
{
    ucParent = LogicalTreeHelper.GetParent(ucParent);
}
Score: 1

You can always use VisualTreeHelper.GetParent(child) to return the parent 2 in the Visual Tree (the parent user control 1 from a nested user control).

Score: 0

UserControl has a .Parent property that 2 should give you access to it's parent.

Then 1 you can cast it to your ParentUC object.

More Related questions