Search code examples
wpfvisualtreehelper

Get ContentPresenter/ItemsPresenter from control


I need a way to access the ContentPresenter/ItemsPresenter from a control if it does exist.

I can't figure out how to easily do this with VisualTreeHelper.

Will I need to recursively search all children?


Solution

  • Yes you need to recurse through the Visual tree....FindVisualChild can do that for you...if you supply it with an instance to the control.

    ContentPresenter myContentPresenter = FindVisualChild(dependencyobject);

    Some links: