绑定到TemplatedParent本身

时间:2013-12-03 10:13:19

标签: c# wpf custom-controls controltemplate

考虑一个自定义控件,在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 本身?如果没有,是否有任何解决方法?

1 个答案:

答案 0 :(得分:1)

也许正在使用

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

nb:如果你打算绑定一个“内容”属性来填充一个控件的“内容”(即视觉孩子),那就不行了......

相关问题