x:Bind vs TemplateBinding inside ControlTemplate

guess_me_if_u_can 126 Reputation points
2024-07-03T09:44:50.88+00:00

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?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
751 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,231 Reputation points Microsoft Vendor
    2024-07-04T01:34:02.78+00:00

    Hello @guess_me_if_u_can,

    It's preferable to use {TemplateBinding} when {TemplateBinding} is capable of covering your requirement, Linking the value of a property in a control template to the value of some other exposed property on the templated control. And also note

    Using x:Bind in a ControlTemplate requires Windows 10, version 1809 (SDK 17763) or later. For more info about target versions, see Version adaptive code.

    If you really care about the performance under different conditions, you can consult it at https://github.com/microsoft/microsoft-ui-xaml/issues.

    0 comments No comments