Gray BackgroundColor in StackLayout Hides RadioButton(s)

Nathan Sokalski 4,121 Reputation points
2021-01-27T22:09:53.01+00:00

I have the following StackLayout:

<StackLayout Orientation="Horizontal" BackgroundColor="Gray" HorizontalOptions="Fill" VerticalOptions="Center" Margin="0" Padding="5,0,0,0" Spacing="0">  

I have tried this line of code with the BackgroundColor set to Green, Red, Transparent, Gray, and Blue. Here are the results:
61020-screenshot-2021-01-27-162240.png

61111-screenshot-2021-01-27-162444.png

61121-screenshot-2021-01-27-162635.png

61057-screenshot-2021-01-27-162838.png

61122-screenshot-2021-01-27-163047.png
Notice that when the BackgroundColor is set to Gray (image 4), the RadioButton circles are missing are missing. Also notice that this is not happening with the other colors, including Transparent. If I create StackLayout(s) with all 5 colors, only the inner part of the RadioButton is visible (the text is always visible, and it allows me to select different RadioButton(s), it just doesn't display the outer part of the button). If I create StackLayout(s) with Green, Red, Transparent, and Blue (but not Gray), only the text of the RadioButton(s) is visible. This seems to be a very strange pattern, especially since the color Gray does not have anything special about it, and the reverse happens with multiple. Any ideas?

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

2 answers

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-01-28T03:48:08.02+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    Yes,by default, the Grid exists with the property RowSpacing and ColumnSpacing.

    When we want to show many views , Gird is recommended.

    And If you don't want the blank space , you can set the RowSpacing to 0 and ColumnSpacing to 0, just as follows:

           <Grid    RowSpacing="0"  ColumnSpacing="0">  
    

    As a test, when I used the following code and set the RowSpacing and ColumnSpacing to 0:

            <Grid BackgroundColor="Transparent" Padding="0" HorizontalOptions="Fill" Margin="0" VerticalOptions="Start" ColumnSpacing="0" RowSpacing="0">  
                <Grid.RowDefinitions>  
                    <RowDefinition Height="Auto" />  
                    <RowDefinition Height="Auto"/>  
                </Grid.RowDefinitions>  
                <Grid.ColumnDefinitions>  
                    <ColumnDefinition Width="*" />  
                    <ColumnDefinition Width="*"/>  
                    <ColumnDefinition Width="*"/>  
                </Grid.ColumnDefinitions>  
      
                    <RadioButton  Content="▲Only" BackgroundColor="Yellow"/>  
      
                    <RadioButton Grid.Column="1"  Content="▼Only" BackgroundColor="Chocolate"/>  
                    <RadioButton Grid.Column="2"  Content="Both" IsChecked="True" BackgroundColor="Blue"/>  
      
                    <RadioButton  Content="▲Only" Grid.Row="1" Grid.Column="0" BackgroundColor="Green"/>  
      
                    <RadioButton   Content="▼Only" Grid.Row="1" Grid.Column="1" BackgroundColor="Green"/>  
                    <RadioButton  Grid.Row="1" Grid.Column="2"  Content="Both" IsChecked="True" BackgroundColor="Green"/>  
      
            </Grid>  
    

    The result is:

    61166-image.png

    And if we not set the ColumnSpacing="0" RowSpacing="0", then the result is:

    61193-image.png

    Hope it can help you.

    Best Regards,

    Jessie Zhang

    ---
    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.


  2. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-01-29T10:02:05.18+00:00

    I did a test, when I used the following code, there is no extra whitespace :

        <StackLayout Spacing="0" BackgroundColor="Gray">  
            <Grid BackgroundColor="Green">  
                <Grid.ColumnDefinitions>  
                    <ColumnDefinition Width="Auto"/>  
                    <ColumnDefinition Width="Auto"/>  
                    <ColumnDefinition Width="Auto"/>  
                    <ColumnDefinition Width="*"/>  
                </Grid.ColumnDefinitions>  
                <Grid.RowDefinitions>  
                    <RowDefinition Height="Auto"/>  
                </Grid.RowDefinitions>  
                <RadioButton Content="▲Only"/>  
                <RadioButton Grid.Column="1" Content="▼Only"/>  
                <RadioButton Grid.Column="2" Content="Both" IsChecked="True"/>  
            </Grid>  
    
    
            <Grid BackgroundColor="Green">  
              <!--the same code of above grid-->  
            </Grid>  
        </StackLayout>  
    

    61760-image.png

    0 comments No comments