Binding to the TemplatedParent itself

271 Views Asked by At

Consider a custom control, with a ControlTemplate defined via Style in a ResourceDictionary:

<Style TargetType="{x:Type local:MyControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MyControl}">
                ....

Some where in that template, I have a ContentControl which I want to set its content to the TemplatedParent itself.

If I bind it to a property on the TemplatedParent it works great:

Content="{TemplateBinding LayoutMode}"

But is there anyway to bind it to the TemplatedParent Itself? And if not are there any workarounds?

1

There are 1 best solutions below

5
On BEST ANSWER

Maybe using

BoundProperty="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MyControl}}

?

nb: if you're intending to bind a "Content" property to fill the "content" (i.e. visual child) of a control, that wont work...