RelativeSource={RelativeSource Mode=TemplatedParent} 有 shorthand 吗?

Is there a shorthand for RelativeSource={RelativeSource Mode=TemplatedParent}?

将模板化父级指定为模板化控件中的绑定源似乎很常见,但冗长得令人恼火。有 shorthand 的方法吗?

路径上的某种前缀似乎更合理。例如

{Binding ^Title}

或类似的东西,而不是

{Binding Title, RelativeSource={RelativeSource Mode=TemplatedParent}}

您可以使用 TemplateBinding:

{TemplateBinding Title}

但是请注意

The types used as the value for the source property and the target property must match. There's no opportunity to introduce a converter when you're using TemplateBinding. Failing to match values results in an error when parsing the XAML. If you need a converter you can use the verbose syntax for a template binding such as: {Binding RelativeSource={RelativeSource TemplatedParent}, Converter="..." ...}

而且,可能更重要的是这里的第二句话:

A TemplateBinding is always a one-way binding. Both properties involved must be dependency properties.