Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Get UserControl owner (the container element)

so I have this UserControl that's inside of another UserControl. Lets call them ParentUC and ChildUC. I need to get ParentUC from ChildUC.

I know to get the window owner would be Window.GetWindow(userControl), but UserControl doesn't have a method like this AFAIK.

Thanks for the help!

like image 231
Carlo Avatar asked Sep 24 '09 22:09

Carlo


1 Answers

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

DependencyObject ucParent = this.Parent;

while (!(ucParent is UserControl))
{
    ucParent = LogicalTreeHelper.GetParent(ucParent);
}
like image 127
Carlo Avatar answered Oct 22 '22 02:10

Carlo