Xamarin.forms Forms-如何将一个元素放置在另一个元素的顶部?

Xamarin.forms Forms-如何将一个元素放置在另一个元素的顶部?,xamarin.forms,Xamarin.forms,我有一个图像滑块,我想在图像滑块顶部放置一个搜索框 这是我的密码: <StackLayout HeightRequest="200" > <cv:CarouselView Margin="0" ItemsSource="{Binding Zoos}" x:Name="CarouselZoos"> <cv:CarouselView.ItemTemplate> <DataTemplate>

我有一个图像滑块,我想在图像滑块顶部放置一个搜索框

这是我的密码:

<StackLayout HeightRequest="200"  >
    <cv:CarouselView Margin="0" ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
        <cv:CarouselView.ItemTemplate>
            <DataTemplate>
                <Image  Grid.RowSpan="1" Grid.Row="0" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
            </DataTemplate>
        </cv:CarouselView.ItemTemplate>
     </cv:CarouselView>
</StackLayout>
<StackLayout>
    <SearchBar FontAttributes="Bold"
        FontFamily="Raleway.ttf#Raleway"
        FontSize="11" 
        Placeholder="SEARCH FOR MEDICINE AND PRODUCTS"  
        HorizontalOptions="Center" VerticalOptions="CenterAndExpand" 
        Focused="SearchBar_Focused"/>
</StackLayout>

最简单的方法是将元素包装到网格中,然后将第二个元素放置到同一网格中

网格布局将把同一单元内的所有元素彼此重叠,最后一个元素添加到最上面

<Grid>
    <Image ... />
    <Label VerticalOptions="Center" HorizontalOptions="Center" />
</Grid>

本例将标签放在图像的中间

使用交互元素时,请记住,它们必须是最后添加的元素,才能单击

比如说,如果你有

 <Grid>
    <Button ... />
    <Image ... />
</Grid>

按钮最终会被图像覆盖,因此无法单击

可能重复的