You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Xamarin Grid中将Label置于Map上方显示?

解决Grid中Label被Map覆盖的问题

在Xamarin.Forms的Grid布局里,元素的渲染顺序由代码中的声明顺序决定——后添加的元素会覆盖先添加的元素。你当前的代码里CustomMap在包含Label的Frame之后声明,所以Map会盖在Label上方。

要让Label显示在Map上方,只需调整元素的声明顺序,把包含Label的Frame放到CustomMap之后即可,无需修改Opacity属性。

修改后的代码如下:

<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">                        
    <local:CustomMap IsShowingUser="True" HasScrollEnabled="True" HasZoomEnabled="True" MapClicked="mapaXaml_MapClicked" x:Name="mapaXaml" Opacity="1"/>
    
    <Frame BackgroundColor="{StaticResource Color2}" Margin="0">
        <Label TextColor="{StaticResource Color5}" FontSize="60" FontAttributes="Bold" x:Name="TituloNombre" HorizontalOptions="CenterAndExpand"></Label>
    </Frame>
</Grid>

调整后,Label会正常显示在Map的上层,即使Map的透明度设为1也不会被遮挡。

内容的提问来源于stack exchange,提问作者Martin Pizarro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 06:55:46