Search code examples
c#wpfparent-childvisualtreehelper

Find visual parent before loaded event was called


Is it possible in WPF to find a visual parent of an object (UIElement) before the loaded event was triggered? If i search for a specific parent in the loaded event, every thing works fine. If i search for a specific parent in the constructor after LoadComponent, it does not work. Or do i have to use the logical tree?

I use the VisualTreeHelper for searching.

Thank you


Solution

  • WPF only inserts the elements into the tree (logical or visual) after the constructor was called. So you cannot find the parent elements in the constructor.

    It wouldn't make sense to insert something that does not exist yet into the tree.