question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RadioButton inside RadioButtonGroup is not initially checked according to binding.

See original GitHub issue

Describe the bug Radio Buttons should be checked according to the bound Value on the RadioButtonGroup, but they are not.

To Reproduce Steps to reproduce the behavior:

  1. Create a new RadioButtonGroupView
  2. Call NewRadioButtonGroup.SetBinding(RadioButtonGroupView.SelectedItemProperty, “PropertyName”) to bind the group to a value in a view model
  3. Create a property in the view model of Enum type with values like “First”, “Second”, “Third”
  4. Set the default value in your view model to “First” (should happen anyway if it’s a non-nullable enum
  5. Add multiple RadioButton instances to your RadioButtonGroupView, making sure one of them has radioButton.Value = MyEnum.First;
  6. Make sure your page has its BindingContext set to an instance of the view model.
  7. Run the project

Expected behavior The expected behavior is when the BindingContext on the Group changes (when the view model is assigned), the group should inspect the current SelectedItem property on the view model and if any contained RadioButtons have that as their Value, the RadioButton should be checked.

Instead, no buttons are checked whatsoever.

Workaround - can get around this by binding to bools that mirror the selected value.

Additional note - I have verified that my binding works correctly because if I check the RadioButtons by tapping on them at runtime, the setter on my view model gets set.

Screenshots

image

Smartphone (please complete the following information):

  • Device: Motorola Moto G6
  • OS: Android 8.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vchelarucommented, Feb 5, 2019

I just tried it, everything works great!

1reaction
vchelarucommented, Feb 5, 2019

I have a simplified scenario which requires no view model nor binding:

        enum MyEnum
        {
            First,
            Second
        }

        void SomeSetupFunction()
        {
            var group = new RadioButtonGroupView();

            var firstButton = new RadioButton("First");
            firstButton.Value = MyEnum.First;
            group.Children.Add(firstButton);

            var secondButton = new RadioButton("Second");
            secondButton.Value = MyEnum.Second;
            group.Children.Add(secondButton);

            // Both radio buttons are part of the group so this should check the
            // "First" radio button
            group.SelectedItem = MyEnum.First;

            // Whatever is needed to add the control to the page

Read more comments on GitHub >

github_iconTop Results From Across the Web

WPF Mvvm Radio Button Binding not setting initial value ...
This causes a problem when a radio button is bound before it is rendered since the value would already be true the animation...
Read more >
Radio buttons rendered with a template not checked ...
My problem is the value I am assigning with a checked binding is not resulting in a checked radio button on the initial...
Read more >
Radio button loses initial 'IsChecked=True' value when ...
RadioButton not selected /checked despite IsChecked=True being set in two column grid layout with two sets of radio button groups #13631.
Read more >
Two radio buttons in group - set is checked of one of them ...
This is a known issue. Radio button loses initial 'IsChecked=True' value when another radio button also has 'IsChecked=True'.
Read more >
The "checked" binding
When the user changes which radio button is selected, Knockout will set your model property to equal the value of the selected radio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found