x:Bind vs TemplateBinding inside ControlTemplate #9796
Replies: 3 comments
-
TemplateBinding is one-way mode, reduce the code behind generating and using, which makes it more lightweight.This is only my thought.I still have the same question. |
Beta Was this translation helpful? Give feedback.
-
TemplateBinding Purpose: Special lightweight binding used only inside ControlTemplates to forward values from the templated parent (the control).
Use Case: Best when you just need to mirror a control’s property in its template (e.g., Foreground, Background). x:Bind Purpose: Compiled binding — works both inside and outside templates. Binding Mode: Defaults to OneTime, but supports OneWay and TwoWay explicitly. Performance: Faster than standard {Binding} (since it’s compiled), but heavier than TemplateBinding in ControlTemplates. Features:
Use Case: Best when you need logic, converters, or TwoWay binding in a template. Limitations:
|
Beta Was this translation helpful? Give feedback.
-
For <ControlTemplate TargetType="SomeCustomControl">
<Grid>
<TextBox Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</ControlTemplate> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/templatebinding-markup-extension#xbind-in-controltemplate
What is the difference between using TemplateBinding and x:Bind inside the ControlTemplate? On the document, it is mentioned that Function Binding and Twoway binding can be done through x:Bind. But is there any internal info that TemplateBinding is more lightweight than x:Bind? Is TemplateBinding better than x:Bind in terms of performance?
Beta Was this translation helpful? Give feedback.
All reactions