Search code examples
c#wpfadorner

Get contentpresenter location (size and offset from owner)


I need a way to dynamically retrieve (not knowing what type of frameworkElement), the content/items presenter size and offset from the owner's edges in any form.

I need to create an adorner that covers the content area of a control.


Solution

  • Use the VisualTreeHelper to identify the ContentPresenter/ItemPresenter from the object if it exists.

    Use the following code to get an offset:

    presenter.TransformToVisual(control).Transform(new Point(0,0));
    

    Call on presenter whatever desired properties that will give you size (Actual[Height/Width], etc.)