Adding command to code behinad

Dani_S 2,886 Reputation points
2024-05-01T12:48:31.42+00:00

Hi,

I have main page and i want to add i used code behaind dor all the menu.

I want to add EulaCommand , how is done ?

Please provide code, i'm using net 8, vs 17.8.4

           `<Label Text="EULA" HorizontalOptions="Start" VerticalOptions="Center" Margin="2,0,0,2" FontSize="14"  TextDecorations="Underline" TextColor="#3398d2"`

ToolTipProperties.Text="Read our terms of use.">

<Label.GestureRecognizers>

<TapGestureRecognizer Command="{Binding EulaCommand}"/>

</Label.GestureRecognizers>

</Label>

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,967 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,946 Reputation points Microsoft Vendor
    2024-05-06T07:17:42.8366667+00:00

    Hello,

    Please refer to the following code:

    XMAL

    <Label...>
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding MultiplyBy2Command}"></TapGestureRecognizer>
                    </Label.GestureRecognizers>
                </Label>
    

    Setting BindingContext for testing

    public MainPage()
    {
         InitializeComponent();
         this.BindingContext = new CommandDemoViewModel();
    }
    

    About the ViewModel , please see Lloyd Sheen's comment. And you also could find this CommandDemoViewModel in the official doc of Button. (Please define properties of type ICommand in your ViewModel)

    For more details, please refer to

    Commanding - .NET MAUI | Microsoft Learn

    Button - .NET MAUI | Microsoft Learn

    Recognize a tap gesture - .NET MAUI | Microsoft Learn

    Data binding and MVVM - .NET MAUI | Microsoft Learn

    Best Regards,

    Wenyan Zhang


    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.
    0 comments No comments

0 additional answers

Sort by: Most helpful