ZIndex Changes Unexpectedly

Nathan Sokalski 4,121 Reputation points

I have a DataTemplate containing several basic elements (a Grid containing Label(s) and Button(s)). Some of the Label(s) are on top of the Button(s) (they have the same Grid.Column & Grid.Row). However, at certain points when I click the Button the Label becomes hidden. If I place them in different cells (different Grid.Column & Grid.Row), they both remain visible. My conclusion from this is that the Button ends up covering the Label. The best solution I can come up with is to explicitly set the ZIndex in the XAML. In UWP, I did this using the attached property Canvas.ZIndex, but this does not seem to be available in Xamarin.Forms. What can I do?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points


    Welcome to Microsoft Q&A!

    Check Layout.RaiseChild(View) Method , it is used to send a child to the front of the visual stack.

    We can make button overlap the label in Gird using this method .

    A simple test on my side , it works as expected.


       <Grid x:Name="grid" >  
               <Grid.RowDefinitions >  
                   <RowDefinition Height="100"/>  
                   <ColumnDefinition Width="100"/>  
               <Button x:Name="button" Text="Click" Clicked="Button_Clicked" BackgroundColor="Red" />  
               <Label Text="123" BackgroundColor="Green" InputTransparent="True"/>  

    Code behind

       private void Button_Clicked(object sender, EventArgs e)  

    Screen shot

    //Before click

    //After click

    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.

    0 comments No comments