考虑一个自定义控件,在ControlTemplate
中通过Style
定义ResourceDictionary
:
<Style TargetType="{x:Type local:MyControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyControl}">
....
在该模板中的某些位置,我有一个ContentControl
,我想将其内容设置为TemplatedParent
本身。
如果我将它绑定到TemplatedParent
上的某个属性,则效果很好:
Content="{TemplateBinding LayoutMode}"
但无论如何将它绑定到TemplatedParent
本身?如果没有,是否有任何解决方法?
答案 0 :(得分:1)
也许正在使用
BoundProperty="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MyControl}}
nb:如果你打算绑定一个“内容”属性来填充一个控件的“内容”(即视觉孩子),那就不行了......