Share via

Cant make a inner stacklayout center...

Carlo Goretti 121 Reputation points
2021-05-17T13:25:22.12+00:00

Hey,

Im trying to make the inner stack layount center but dosent get it to work...
When im reading on stackoverflow then i do right but it dosent work...
Any ideas?

    <ContentPage.Content>
        <Frame StyleId="FrameContent">
            <StackLayout Spacing="20" BackgroundColor="LightPink">
                <StackLayout>
                    <Image Source="Base_Logo.png"></Image>
                </StackLayout>




                <StackLayout VerticalOptions="Center" 
                             HorizontalOptions="Center"

                             BackgroundColor="LightBlue">
                    <Label x:Name="WelcomeHeaderLbl"
                           StyleId="LblHeader"
                           FontSize="28"
                           HorizontalOptions="Center">
                    </Label>
                    <Picker x:Name="LanguagePicker"
                            StyleId="LanguagePicker"
                            HorizontalOptions="Center"
                            VerticalOptions="Center"
                            Title="Choose Language">
                    </Picker>
                </StackLayout>




                <StackLayout>
                    <Button x:Name="ContinueButton"
                            StyleId="ContinueButton"
                            Clicked="ContinueButton_Clicked"
                            HorizontalOptions="Center">
                    </Button>
                </StackLayout>
            </StackLayout>
        </Frame>
    </ContentPage.Content>

The stacklayout with space around it is the one that should be center...

Developer technologies | .NET | Xamarin
0 comments No comments

Answer accepted by question author

JessieZhang-MSFT 7,721 Reputation points Microsoft External Staff
2021-05-18T05:53:18.733+00:00

Hello,

Welcome to our Microsoft Q&A platform!

Try to change the VerticalOptions from value Center to VerticalOptions.

VerticalOptions="CenterAndExpand"

The code is:

<ContentPage.Content>  
    <Frame StyleId="FrameContent">  
        <StackLayout Spacing="20" BackgroundColor="LightPink">  
            <StackLayout>  
                <Image Source="image.png"></Image>  
            </StackLayout>  

            <StackLayout VerticalOptions="CenterAndExpand"   
                          HorizontalOptions="Center"  
                            
                          BackgroundColor="LightBlue">  
                <Label x:Name="WelcomeHeaderLbl"  
                        StyleId="LblHeader"  
                        FontSize="28"  
                        HorizontalOptions="Center">  
                </Label>  
                <Picker x:Name="LanguagePicker"  
                         StyleId="LanguagePicker"  
                         HorizontalOptions="Center"  
                         VerticalOptions="Center"  
                         Title="Choose Language">  
                </Picker>  
            </StackLayout>  
            <StackLayout>  
                <Button x:Name="ContinueButton"  
                        Text="test button"  
                         StyleId="ContinueButton"  
                         HorizontalOptions="Center">  
                </Button>  
            </StackLayout>  
        </StackLayout>  
    </Frame>  
</ContentPage.Content>  

The result is:

97393-image.png

Best Regards,

Jessie Zhang

---
If the response is helpful, please click "Accept Answer" and upvote it.

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.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

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.