Search code examples
c#xamlmaui

Before the form is displayed, all radio buttons belong to the same radio group


I have two groups of radio buttons, I need the first radio button in each group to be checked as default, but for some reason, after starting, only the last one that I checked is checked, and it does not matter if I do it from code or in the layout, after showing the form, the groups work correctly, but are not initialized correctly, here is an example and the result:

<StackLayout>
        <StackLayout>
            <RadioButton GroupName="1" Content="1.1" IsChecked="True"/>
            <RadioButton GroupName="1" Content="1.2"/>
        </StackLayout>
        
        <StackLayout>
            <RadioButton GroupName="2" Content="2.1" IsChecked="True"/>
            <RadioButton GroupName="2" Content="2.2"/>
        </StackLayout>
    </StackLayout>

the result:

enter image description here

while expected result should be:

enter image description here

I tried changing the layout, grouping the radio buttons in different ways, but that didn't help.


Solution

  • I created a new project with your code and I can reproduce your problem in my project. But this problem only appeared on the windows platform. I can get the expected result when I tested it on the android.

    In addition, I found it is a known issue on the github. You can follow up this issue about RadioButton GroupName and IsChecked properties work inconsistently on Windows.