bug RadioButton not aligned IOS or problem IsEnabled ANDROID

delaio 306 Reputation points
2020-12-16T16:35:24.067+00:00

Hello,
The alignment of radio buttons in iOS differs when changing the visibility of the parent layout.
https://github.com/xamarin/Xamarin.Forms/issues/11383

I am currently unable to install version 5.0.0.1558-pre3 and I have not been able to apply their workaround.

Instead of managing IsVisible, I decided to manage IsEnabled at false and Opacity at 0. It works very well on IOS, but it no longer works on Android: the first tab is always disabled.

I don't know if I'm missing a basic error or if it's a bug. Do you have a solution to suggest?
thank you so much.

PageConnection.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="pb_alignment_radiobt.PageConnection">
    <NavigationPage.TitleView>
        <Label x:Name="labelnavigationpage_lb"/>
    </NavigationPage.TitleView>

    <ContentPage.Content>

        <Grid>
            <StackLayout>
                <Grid BackgroundColor="White"
                      VerticalOptions="FillAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid BackgroundColor="white"
                          Grid.Row="0">
                        <Grid.RowDefinitions>
                            <!--tabcontrol-->
                            <RowDefinition Height="auto" />
                            <!--tab-->
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <!-- tabcontrol -->
                        <Grid Grid.Row="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="0.5*" />
                                <ColumnDefinition Width="0.5*" />
                            </Grid.ColumnDefinitions>
                            <Button x:Name="connection_bt"
                                    Grid.Column="0"
                                    Text="I CONNECTED"
                                    TextColor="Black"
                                    BackgroundColor="Transparent"
                                    BorderColor="Transparent"
                                    BorderWidth="0"
                                    Clicked="ShowTabControl" />
                            <BoxView x:Name="connection_bord"
                                     Grid.Column="0"
                                     HeightRequest="1"
                                     HorizontalOptions="FillAndExpand"
                                     VerticalOptions="EndAndExpand"
                                     Color="Black" />
                            <Button x:Name="recording_bt"
                                    Grid.Column="1"
                                    Text="I'M REGISTERING"
                                    TextColor="Gray"
                                    BackgroundColor="Transparent"
                                    BorderColor="Transparent"
                                    BorderWidth="0"
                                    Clicked="ShowTabControl" />
                            <BoxView x:Name="registration_bord"
                                     Grid.Column="1"
                                     IsVisible="false"
                                     HeightRequest="1"
                                     HorizontalOptions="FillAndExpand"
                                     VerticalOptions="EndAndExpand"
                                     Color="Black" />
                        </Grid>
                        <!-- tab CONNECTION -->
                        <StackLayout x:Name="connection_ong"
                                     BackgroundColor="Aquamarine"
                                     Grid.Row="1"
                                     IsEnabled="True"
                                     Opacity="1"
                                     VerticalOptions="Fill"
                                     Margin="20,5,20,0">
                                <RadioButton x:Name="email_rb"
                                             BackgroundColor="Blue"
                                             Grid.Column="0"
                                             Text="Email"
                                             TextColor="Black"
                                             IsChecked="true"
                                         GroupName="connection"
                                         VerticalOptions="Start" />
                                <RadioButton x:Name="mobile_rb"
                                             BackgroundColor="Green"
                                             Grid.Column="1"
                                             Text="Mobile"
                                             TextColor="Black"
                                         GroupName="connection"
                                         VerticalOptions="Start" />
                        </StackLayout>
                        <!-- tab registration -->
                        <StackLayout x:Name="registration_ong"
                                     BackgroundColor="Yellow"
                                     Grid.Row="1"
                                     VerticalOptions="Fill"
                                     Margin="20,5,20,0">
                                <RadioButton x:Name="nvemail_rb"
                                             BackgroundColor="Brown"
                                             Grid.Column="0"
                                             Text="New Email"
                                             TextColor="Black"
                                             IsChecked="true"
                                             GroupName="nvconnection"
                                             VerticalOptions="Start" />
                                <RadioButton x:Name="nvmobile_rb"
                                             BackgroundColor="Purple"
                                             Grid.Column="1"
                                             Text="New Mobile"
                                             TextColor="Black"
                                             GroupName="nvconnection"
                                             VerticalOptions="Start" />
                        </StackLayout>
                    </Grid>
                </Grid>
            </StackLayout>
        </Grid>
    </ContentPage.Content>
</ContentPage>

PageConnection.xaml.cs

    public partial class PageConnection : ContentPage
    {

        public PageConnection(string tab_st)
        {
            InitializeComponent();
            BindingContext = this;

            if (tab_st == "signIn")
               ShowTabControl(connection_bt, null);
            else // (tab_st == "Register")
               ShowTabControl(recording_bt, null);

        }

        private void ShowTabControl(object sender, EventArgs e)
        {
            try
            {
                if ((sender as Button) == connection_bt)
                {
                    connection_ong.IsEnabled = true;
                    connection_ong.Opacity = 1;
                    registration_ong.IsEnabled = false;
                    registration_ong.Opacity = 0;

                    connection_bt.TextColor = Color.Black;
                    connection_bord.IsVisible = true;
                    recording_bt.TextColor = Color.Gray;
                    registration_bord.IsVisible = false;
                    labelnavigationpage_lb.Text = "I already have an account";
                }
                else if ((sender as Button) == recording_bt)
                {
                    registration_ong.IsEnabled = true;
                    registration_ong.Opacity = 1;
                    connection_ong.IsEnabled = false;
                    connection_ong.Opacity = 0;

                    connection_bt.TextColor = Color.Gray;
                    connection_bord.IsVisible = false;
                    recording_bt.TextColor = Color.Black;
                    registration_bord.IsVisible = true;
                    labelnavigationpage_lb.Text = "I register";
                }
            }
            catch (Exception ex)
            {

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

Accepted answer
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2020-12-17T07:51:39.583+00:00

    Hello,

    Welcome to Microsoft Q&A!

    As hartez mentioned in the issue , upgrading Xamairn.Forms to 5.0.0.1558-pre3. resolves the problem .

    49035-capture.png

    To select the prerelease version you need to enable this option .

    49027-cap2ture.png

    And don't forget to change Text properties to Content on RadioButton.

    Thank you.


    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.


1 additional answer

Sort by: Most helpful
  1. delaio 306 Reputation points
    2020-12-16T21:48:39.16+00:00

    i placed a build directive but if there is a cleaner solution, i take. ;o)

                        if (Device.RuntimePlatform == Device.Android)
                        {
                            connection_ong.IsVisible = true;
                            registration_ong.IsVisible = false;
                        }
    
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            connection_ong.IsEnabled = true;
                            connection_ong.Opacity = 1;
                            registration_ong.IsEnabled = false;
                            registration_ong.Opacity = 0;
                        }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.