TextProperty': derive content

Eduard Kaufmann 211 Reputation points
thanks for your time ... I'm having a blackout !
environment: VS2022, .net7, MAUI

How can I derive the content of the TextProperty: in this case 'Siou Blanc'?

I used n variations without success ... must be blind!
string location = Button.TextProperty.ToString();
// result: location = 'Text'
        Command="{Binding MCommand}"
        IsEnabled="{Binding IsNotBusy}"
        Style="{StaticResource ButtonOutline}"
        Text="Siou Blanc"/>
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,589 questions
{count} votes

Accepted answer
  1. Viorel 109.9K Reputation points

    Try assigning a name: <Button x:Name="button1" ....

    In the associated code file: string location = button1.Text.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 64,011 Reputation points Microsoft Vendor


    You can do this by adding CommandParameter="{x:Reference button1}" in the Button like following code.

        <Button x:Name="button1"
                Command="{Binding VARhCommand}"
                CommandParameter="{x:Reference button1}"
                IsEnabled="{Binding IsNotBusy}"
                Style="{StaticResource ButtonOutline}"

    Then add an attribute in your VARhAsync of HikesViweModel.cs. You can get the button text in the ViewModel.

        async Task VARhAsync(Button btn)    {
            string location = btn.Text;

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    1 person found this answer helpful.