.NET MAUI RadioButtonGroup.SelectedValue does not work

Crowcoder 50 Reputation points
2025-01-04T22:11:20.1466667+00:00

I can't get RadioButtonGroup.SelectedValue to bind to a viewmodel property. I've read everything that you can google including:

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/radiobutton?view=net-maui-9.0#respond-to-a-property-change

https://github.com/dotnet/maui-samples/blob/main/9.0/UserInterface/Views/RadioButtonDemos/RadioButtonDemos/Views/GroupedRadioButtonsViewModelPage.xaml

and other questions asked here.

I have made a simplified example to eliminate extraneous issues. I don't get it, it should work and it should be simple based on documentation.

View

   ...
<Grid>
       <ScrollView >
           <VerticalStackLayout HorizontalOptions="Center" Padding="20,0,20,0" >
               <Label Text="Select the course:"></Label>
               <VerticalStackLayout RadioButtonGroup.SelectedValue="{Binding SelectedThing}">
                   <RadioButton GroupName="FOO" Content="ONE" Value="1"></RadioButton>
                   <RadioButton GroupName="FOO" Content="TWO" Value="2" ></RadioButton>
                   <RadioButton GroupName="FOO" Content="THREE" Value="3"></RadioButton>
               </VerticalStackLayout>
               <Label Text="{Binding SelectedThing, StringFormat='The selection is: {0} (not working!)'}"></Label>
...

ViewModel

(based on mvvm toolkit ObservableObject)

 [ObservableProperty]
 private object selectedThing;

User's image

I'm not sure what else might be relevant.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,870 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
830 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Crowcoder 50 Reputation points
    2025-01-05T14:12:33.8333333+00:00

    I had to put GroupName at the same level as SelectedValue like this:

    <VerticalStackLayout RadioButtonGroup.GroupName="FOO" RadioButtonGroup.SelectedValue="{Binding SelectedThing}">

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.