我有一个具有这种结构的ContentView元素:
<ContentView>
<StackLayout>
<Grid>
...
</Grid>
<ActivityIndicator>
...
</ActivityIndicator>
</StackLayout>
</ContentView>
,我需要将其放在页面的中央。我是WPF的新手,我不知道该怎么做。欢迎任何建议。
答案 0 :(得分:0)
只需将Center用作ContentView的LayoutOptions
<ContentView HorizontalOptions="Center" VerticalOptions="Center">
<StackLayout>
<Grid>
...
</Grid>
<ActivityIndicator>
...
</ActivityIndicator>
</StackLayout>
</ContentView>
答案 1 :(得分:0)
我找到了答案。我对Shiblu'a的回答是,ContentView的中心在水平轴上,而在垂直轴上却不在。它从屏幕中间开始,然后下降。因此,如果ContentView为200 * 300,屏幕为1000 * 1000,则ContentView将在其上方500 px,在其下方200 px。我已改正为负的保证金值
<ContentView HeightRequest="170" WidthRequest="450" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Margin="0, -85, 0, 0">
<StackLayout>
<Grid>
...
</Grid>
<ActivityIndicator>
...
</ActivityIndicator>
</StackLayout>
</ContentView>