Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radio button loses initial 'IsChecked=True' value when another radio button also has 'IsChecked=True' #11418

Closed
andycambo opened this issue Nov 16, 2022 · 6 comments · Fixed by #13611
Assignees
Labels
area-controls-radiobutton RadioButton, RadioButtonGroup fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! platform/windows 🪟 t/bug Something isn't working

Comments

@andycambo
Copy link

andycambo commented Nov 16, 2022

Description

There is an issue when trying to use multiple radio buttons on a page.

If there are two radio buttons set to 'IsChecked=True' then only the last button in the view will remain true - despite them being given different GroupNames and in separate parent containers.
image

Initial thoughts are that it appears that all the radio buttons on the view are treated as one group (tried to give the control different GroupNames as shown in example) and therefore, as the view is rendered in order, only the last radio button with IsChecked=True will keep its initial value, earlier radio buttons will be set to be unchecked.
image

In Android, the expected result is shown. I have been unable to test the remaining platforms.
image

Steps to Reproduce

Create a new solution.
Add to view multiple radio buttons with IsChecked=True

<VerticalStackLayout Spacing="25">

            <VerticalStackLayout>
                <RadioButton GroupName="First" Content="First" IsChecked="True"/>
            </VerticalStackLayout>

            <VerticalStackLayout>
                <RadioButton GroupName="Middle" Content="Middle" IsChecked="True"/>
            </VerticalStackLayout>

            <VerticalStackLayout>
                <RadioButton GroupName="Last" Content="Last" IsChecked="True"/>
            </VerticalStackLayout>

</VerticalStackLayout>

Link to public reproduction project repository

https://github.com/andycambo/MauiRadioButtonBugExample

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

@andycambo andycambo added the t/bug Something isn't working label Nov 16, 2022
@Eilon Eilon added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Nov 16, 2022
@PureWeen PureWeen added this to the Backlog milestone Nov 16, 2022
@ghost
Copy link

ghost commented Nov 16, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@danielancines
Copy link

I got the shame problem here, when you create two separated layouts under the same BindingContext, the property RadioButtonGroup.SelectedValue works fine, but, even if you use different RadioButtonGroup.GroupName, occurs the same problem as @andycambo mentioned above, only the second pair of RadioButtons respect the initial binding, the first loaded unchecked.

`

<ScrollView>
    <VerticalStackLayout
        Spacing="25"
        Padding="30,0"
        VerticalOptions="Center">
        <HorizontalStackLayout RadioButtonGroup.GroupName="Z"
                               RadioButtonGroup.SelectedValue="{Binding ImportExcelSelectedOption}">
            <RadioButton Content="Option 1" Value="grupo_cliente"/>
            <RadioButton Content="Option 2" Value="grupo_primeiro_depois_mft" Margin="10,0,0,0"/>
        </HorizontalStackLayout>

        <HorizontalStackLayout RadioButtonGroup.GroupName="Z1"
                               RadioButtonGroup.SelectedValue="{Binding ExportExcelSelectedOption}">
            <RadioButton Grid.Column="2"
                         Content="Option 1" Value="grupo_cliente"/>
            <RadioButton Grid.Column="3" Margin="10,0,0,0"
                         Content="Option 2" Value="grupo_primeiro_depois_mft"/>
        </HorizontalStackLayout>
        <Button Clicked="Button_Clicked" Text="tes"/>
    </VerticalStackLayout>
</ScrollView>
`

@mouralabank
Copy link

Same problem here.

@hartez
Copy link
Contributor

hartez commented Feb 1, 2023

Apparently this is a known bug in WinUI: microsoft/microsoft-ui-xaml#2081

And I can reproduce that issue in UWP as well, so it's been a problem for a while. Not sure if we've ever run into this in Forms; if not, I wonder what we did that prevented it.

@hartez
Copy link
Contributor

hartez commented Feb 1, 2023

Okay, I think we can hack around this in .NET MAUI until microsoft/microsoft-ui-xaml#2081 gets fixed. It's a little gross, but I think it'll work:

  1. When creating the platform RadioButton in RadioButtonHandler.Windows, we'll need to set the native GroupName property to something unique (maybe a GUID). That will prevent the native IsChecked conflicts.
  2. At some point after the native controls have resolved their containers, we can clear the native GroupName property. It seems to stop being a problem after the initial layout, so I'm betting if we cleared the property after the first PlatformArrange call in RadioButtonHandler.Windows we'd be good.

@jstedfast jstedfast self-assigned this Feb 24, 2023
@jstedfast
Copy link
Member

Just confirmed with VS 2022 17.5.0

jstedfast added a commit that referenced this issue Feb 28, 2023
@samhouts samhouts modified the milestones: Backlog, .NET 8 Planning Mar 2, 2023
jstedfast added a commit that referenced this issue Mar 3, 2023
### Description of Change

This change sets a unique GroupName on every WinUI RadioButton created
so that different groups of MAUI RadioButtons are not assumed by WinUI
to share the same group and thus prevent IsChecked values from being set
properly.

### Issues Fixed

Fixes #11418
@samhouts samhouts added the fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! label Apr 12, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-radiobutton RadioButton, RadioButtonGroup fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants