0
votes

I have a ContentView element of this structure:

<ContentView>
    <StackLayout>
        <Grid>
            ...
        </Grid>
        <ActivityIndicator>
            ...
        </ActivityIndicator>
    </StackLayout> 
</ContentView>

and i need to put it on the center of a page. I am new to WPF and i don't know how to do it. Any suggestions are welcomed.

2
Did you try with HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" ? - FabriBertani
Is this question about WPF or Xamarin.Forms? Please remove the tag that misfits. - Paul Kertscher
Thank you, see my comment on Shiblu's response - Petru Ritivoiu
My bad, i removed it. - Petru Ritivoiu

2 Answers

0
votes

Just use Center as LayoutOptions for the ContentView

<ContentView HorizontalOptions="Center" VerticalOptions="Center">
    <StackLayout>
        <Grid>
            ...
        </Grid>
        <ActivityIndicator>
            ...
        </ActivityIndicator>
    </StackLayout>
</ContentView>
0
votes

I found the answer. My problem with Shiblu'a answer was that the ContentView was centered on the horizontal axis but on the vertical axis it was not. It started from the middle of the screen and went down. So, if the ContentView was 200*300, and the screen was 1000*1000, the ContentView will have 500 px above him and 200 px bellow him. I have corrected that with a negative Margin value

<ContentView HeightRequest="170" WidthRequest="450" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Margin="0, -85, 0, 0">
  <StackLayout>
    <Grid>
        ...
    </Grid>
    <ActivityIndicator>
        ...
    </ActivityIndicator>
  </StackLayout>
</ContentView>