xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] RadioButtons with two or more groups doesn't initialize correctly in UWP #14271

Open jessiezh0320 opened 3 years ago

jessiezh0320 commented 3 years ago

Description

RadioButtons with two or more groups doesn't initialize correctly in UWP.

Steps to Reproduce

  1. create a new xamarin forms app and use the following code in one page;

       <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="100" />
             <RowDefinition Height="100" />
         </Grid.RowDefinitions>
    
         <StackLayout RadioButtonGroup.GroupName="People"
                  Grid.Row="0">
             <RadioButton 
                 GroupName="Person"
                 Content="Bob"/>
             <RadioButton
                 GroupName="Person"
                 Content="Ray"
                 IsChecked="True"/>
         </StackLayout>
    
         <StackLayout RadioButtonGroup.GroupName="Colours" 
                      Grid.Row="1">
             <RadioButton
                 GroupName="Colour"
                 Content="Red"
                 IsChecked="True"/>
             <RadioButton 
                 GroupName="Colour"
                 Content="Yellow"/>
         </StackLayout>
     </Grid>
  2. please use the latest version of nuget xamarin form(5.0.0.2012) and Xamarin.Essentials v1.6.1.
  3. build and deploy to uwp ;

Expected Behavior

Hope the RadioButtons with two or more groups could initialize correctly in uwp.

Actual Behavior

RadioButtons with two or more groups doesn't initialize correctly in UWP. image

Basic Information

Environment

pledi commented 3 years ago

I also encounter the described problem when working with two or more RadioButtonGroups on a UWP build.

zleao commented 3 years ago

Same here! Once the second group is created, the first one will get all its RadioButtons unselected

holecekp commented 2 years ago

I have the same problem. The bug is also in the latest 5.0.0.2244. I have found two possible workarounds:

Workaroud 1: Use a ControlTemplate. Only RadioButtons without ControlTemplate are affected.

Workaround 2: If you have your code for setting the initial values for RadioButtons in a method named e.g. InitRadioButtons(), do not call it directly. Instead, put the following line at the end of OnAppearing:

Task.Run(() => MainThread.InvokeOnMainThreadAsync(InitRadioButtons));