Skip to content

Commit 075d7a9

Browse files
bjarnesvanbergBillWagner
authored andcommitted
Mention how to achieve two-way binding (#6439)
After reading [this question on StackOverflow](https://stackoverflow.com/questions/5913176/in-wpf-why-doesnt-templatebinding-work-where-binding-does) I think it should be noted in the Remarks section what is necessary to get two-way binding to work with a template binding. Right now the Remarks section only tell us that "A TemplateBinding is always a one-way binding..." which suggest that it is not possible to make a two-way binding to a templated parent.
1 parent e73d849 commit 075d7a9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/framework/wpf/advanced/templatebinding-markup-extension.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Links the value of a property in a control template to be the value of another p
3232
|`sourceProperty`|Another dependency property that exists on the type being templated, specified by its <xref:System.Windows.DependencyProperty.Name%2A?displayProperty=nameWithType>.<br /><br /> - or -<br /><br /> A "dotted-down" property name that is defined by a different type than the target type being templated. This is actually a <xref:System.Windows.PropertyPath>. See [PropertyPath XAML Syntax](../../../../docs/framework/wpf/advanced/propertypath-xaml-syntax.md).|
3333

3434
## Remarks
35-
A `TemplateBinding` is an optimized form of a [Binding](../../../../docs/framework/wpf/advanced/binding-markup-extension.md) for template scenarios, analogous to a `Binding` constructed with `{Binding RelativeSource={RelativeSource TemplatedParent}}`. A `TemplateBinding` is always a one-way binding, even if properties involved default to two-way binding. Both properties involved must be dependency properties.
35+
A `TemplateBinding` is an optimized form of a [Binding](../../../../docs/framework/wpf/advanced/binding-markup-extension.md) for template scenarios, analogous to a `Binding` constructed with `{Binding RelativeSource={RelativeSource TemplatedParent}}`. A `TemplateBinding` is always a one-way binding, even if properties involved default to two-way binding. Both properties involved must be dependency properties. In order to achieve two-way binding to a templated parent use the following binding statement instead
36+
`{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Path=MyDependencyProperty}`.
3637

3738
[RelativeSource](../../../../docs/framework/wpf/advanced/relativesource-markupextension.md) is another markup extension that is sometimes used in conjunction with or instead of `TemplateBinding` in order to perform relative property binding within a template.
3839

0 commit comments

Comments
 (0)