TextProperty': derive content

asked 2023-01-13T07:30:09.3266667+00:00
Eduard Kaufmann 41 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.
874 questions
{count} votes

Accepted answer
  1. answered 2023-01-13T09:25:35.0766667+00:00
    Viorel 82,381 Reputation points

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

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

1 additional answer

Sort by: Most helpful
  1. answered 2023-01-20T05:49:57.2166667+00:00
    Leon Lu (Shanghai Wicresoft Co,.Ltd.) 41,396 Reputation points Microsoft Employee


    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.