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)
{
}
}
}