A community member has associated this post with a similar question:
How to bind ControlTemplate's child property to other element with xaml?

Only moderators can edit this content.

How to set child of ControlTemplate as Binding source?

Anonymous
2021-03-08T12:41:01.007+00:00

Here i have a control template which has label as its child.
Now i want to get properties of that label like text or width.
How to achieve this with xaml?

<ControlTemplate x:key="MyLabel">
<Label
Text="This Is a Button"
/>
</ControlTemplate>

<Button
Text="{Binding Source={x:Reference MyLabel}, Path=Text}" />
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,261 Reputation points Microsoft Vendor
    2021-03-08T14:35:05.393+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    No, you cannot get Width of ControlTemplate, ControlTemplate do not extend VisualElement, If a control extend VisualElement will have Width property that you can bind it.

    75478-image.png

    75484-image.png

    Best Regards,

    Leon Lu


    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.