Layout doesn't stick to my option

Eduardo Gomez Romero 1,375 Reputation points
2024-03-27T18:13:35.5366667+00:00

This is my xaml

<Border
    BackgroundColor="#E1E4D8"
    HorizontalOptions="Center"
    VerticalOptions="Center"
    WidthRequest="800">

    <VerticalStackLayout
        HorizontalOptions="CenterAndExpand"
        VerticalOptions="CenterAndExpand">

        <Label
            Padding="10"
            FontAttributes="Bold"
            FontSize="Medium"
            HorizontalOptions="Center"
            Text="{Binding WelcomeText}" />

        <Border
            Margin="0,10,0,0"
            Padding="10"
            VerticalOptions="Center">
            <VerticalStackLayout
                BackgroundColor="#6D6D2B"
                BindableLayout.ItemsSource="{Binding Roles}"
                HorizontalOptions="FillAndExpand">
                <BindableLayout.ItemTemplate>
                    <DataTemplate x:DataType="model:UserRoles">
                        <Border
                            Margin="10"
                            BackgroundColor="{Binding SelectedColor}">
                            <Label
                                Margin="10"
                                HorizontalTextAlignment="Center"
                                Text="{Binding Name}" />
                            <Border.GestureRecognizers>
                                <TapGestureRecognizer
                                    Command="{Binding Path=RoleSelectedCommand, Source={x:RelativeSource AncestorType={x:Type vm:RoleSelectionPageViewModel}}}"
                                    CommandParameter="{Binding .}" />
                            </Border.GestureRecognizers>
                        </Border>
                    </DataTemplate>
                </BindableLayout.ItemTemplate>
            </VerticalStackLayout>
        </Border>

        <Button
            Margin="0,20,0,20"
            BackgroundColor="#007BFF"
            Command="{Binding UpdateUserCurrentRoleCommand}"
            CornerRadius="5"
            Text="Select role"
            TextColor="White" />

    </VerticalStackLayout>
</Border>


If I run

User's image

If I fix it

 <Border
     Margin="0,10,0,0"
     Padding="10"
     VerticalOptions="Center">
     <VerticalStackLayout
         BackgroundColor="#6D6D2B"
         BindableLayout.ItemsSource="{Binding Roles}">
         <BindableLayout.ItemTemplate>
             <DataTemplate x:DataType="model:UserRoles">
                 <Border
                     Margin="10"
                     BackgroundColor="{Binding SelectedColor}"
                     HorizontalOptions="FillAndExpand">
                     <Label
                         Margin="10"
                         HorizontalTextAlignment="Center"
                         Text="{Binding Name}" />
                     <Border.GestureRecognizers>
                         <TapGestureRecognizer
                             Command="{Binding Path=RoleSelectedCommand, Source={x:RelativeSource AncestorType={x:Type vm:RoleSelectionPageViewModel}}}"
                             CommandParameter="{Binding .}" />
                     </Border.GestureRecognizers>
                 </Border>
             </DataTemplate>
         </BindableLayout.ItemTemplate>
     </VerticalStackLayout>
 </Border>

 <Button
     Margin="0,20,0,20"
     BackgroundColor="#007BFF"
     Command="{Binding UpdateUserCurrentRoleCommand}"
     CornerRadius="5"
     Text="Select role"
     TextColor="White" />

User's image

but if I run it again I get

User's image

Why

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Eduardo Gomez Romero 1,375 Reputation points
    2024-03-28T01:05:12.2266667+00:00

    It was a problem with the first stacklayout


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.