ICommand Command not working in Maui Preview 11

Solution 1:

I was able to get it to work, by making 2 changes. However, these changes affect the vertical spacing of the page. See if this works for you, then try to find a different way to get the desired layout.

  1. Remove VerticalOptions="EndAndExpand" from StackLayout.

  2. Remove VerticalOptions="StartAndExpand" from Label.

Login.xaml:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiTests.Login"
             Title="Login"
             BackgroundColor="White">
    <StackLayout>
        <Button Text="LOGIN"
                    MaximumHeightRequest="45"
                    CornerRadius="10"
                    HeightRequest="45"
                    TextColor="White"
                    Margin="2"
                    BackgroundColor="#620774"
                    Command="{Binding LoginCommand}"/>

        <!-- VerticalOptions="EndAndExpand" -->
        <StackLayout Margin="10" Padding="20">

            <Border Stroke="#620774"
                    StrokeThickness="4"
                    Padding="16,8"
                    BackgroundColor="Transparent"
                    HorizontalOptions="Center">
                <Border.StrokeShape>
                    <RoundRectangle CornerRadius="5,5,5,5" BackgroundColor="Transparent"/>
                </Border.StrokeShape>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <!--Email Address-->

                    <Entry
                        GridLayout.Column="1"
                        GridLayout.Row="0"
                        PlaceholderColor="#9d2888"
                        Margin="4,0,0,0"
                        TextColor="Black"
                        HeightRequest="50"
                        Placeholder="Email Address"
                        Keyboard="Email"/>



                    <!--Password-->
                    <Entry
                        GridLayout.Column="1"
                        GridLayout.Row="1"
                        HeightRequest="50"
                        Margin="4,0,0,0"
                        PlaceholderColor="#9d2888"
                        TextColor="Black"
                        Placeholder="Password"
                        IsPassword="True"/>

                </Grid>
            </Border>

            <!-- VerticalOptions="StartAndExpand" -->
            <Label Text="Forgot Password?"
                   HorizontalOptions="Center"
                   Margin="0,15,0,15"
                   
                   TextColor="#0052FF">
                <Label.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding ForgotPassword}"/>
                </Label.GestureRecognizers>
            </Label>

        </StackLayout>


        <Button Text="Dont have an account? Register here!"
                    MaximumHeightRequest="45"
                    CornerRadius="10"
                    HeightRequest="45"
                    TextColor="White"
                    BackgroundColor="#620774"
                    Margin="2"
                    Command="{Binding RegisterCommand}"/>
    </StackLayout>
</ContentPage>