Share via

Proper transition from TemplateBinding...

Gary Lewis 256 Reputation points
2020-12-12T21:38:56.637+00:00

According to the documentation, TemplateBinding is now Obsolete. The docs say only, " Use Binding.Source=RelativeBindingSource.TemplatedParent". I've been struggling with ControlTemplates and can't figure out the proper way to transition from using TemplateBinding to Binding.Source=RelativeBindingSource.TemplatedParent. Sample code would certainly be useful here.

Is anyone else having similar difficulties? Can someone point to an example of the correct usage? TIA!

Developer technologies | .NET | Xamarin
0 comments No comments

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2020-12-17T05:48:59.773+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Hi, the RelativeSource markup extension represents the relative bindings which provides the ability to set the binding source relative to the position of the binding target. The RelativeSource markup extension is supported by the RelativeSourceExtension class. RelativeSourceExtension defines the Mode property.

    TemplatedParent is one number of the Mode values, it indicates the element to which the template, in which the bound element exists, is applied.

    Here are the related docs, you could refer to:
    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/relative-bindings
    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/relative-bindings#bind-to-a-templated-parent

    You could check the official sample code -- RelativeSourceBindingCardViewPage:
    https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/databindingdemos/

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.