2
votes

Here is my XAML showing the first radio button being checked, yet when the form shows, none are selected.

When I click around on the form, the radio buttons behave as expected.

<StackPanel Margin="20,0" Orientation="Horizontal">
    <TextBlock Margin="0,0,10,0" VerticalAlignment="Center" Text="Search with:" />
    <RadioButton x:Name="rdoDates" Content="Dates" IsChecked="True" />
    <RadioButton x:Name="rdoTags" Content="Tags" IsChecked="False" />
    <RadioButton x:Name="rdoBoth" Content="Both" IsChecked="False" />
</StackPanel>

Update As I understand it, if your radiobuttons are inside a containing element, like a stackpanel or what ever you do not need a GroupName and adding IsChecked=True to one of them works, so I did not use a groupname. Everything works fine until you add a second group of radiobuttons later in the page flow that has one item IsChecked=True. The IsChecked property gets applied to the second group of radio buttons and the first one goes unchecked.

Once I applied a GroupName to each set of radiobuttons, the IsChecked was respected for each group.

3
Are you sure you don't have any code that that can mess this up? I cannot reproduce it, when I launch sample app with your xaml - the first button is checked as expected.RTDev
Please provide more information, because if I copy/paste this snippet to a clean project it works good.Tóth Tibor

3 Answers

3
votes

I had same problem in UWP and using GroupName fixed it! I also used x:Bind to be able debug, but it didn't help.

<StackPanel Orientation="Vertical">
                    <RadioButton x:Uid="radioButtonOriginalMap"
                                 Tag="OriginalMap"
                                 GroupName="Map"
                                 IsChecked="{x:Bind Vm.IsRadarOriginalMapChecked, Mode=TwoWay}"/>
                    <RadioButton x:Uid="radioButtonBingMap"
                                 GroupName="Map"
                                 Tag="BingMap"
                                 IsChecked="{x:Bind Vm.IsRadarBingMapChecked, Mode=TwoWay}"/>
</StackPanel>
0
votes

I faced similar problems as well. I don't exactly know why this happens. But to be sure that the radiobutton is checked every time, I did in the contructor of the page from the code behind.

0
votes

Late to the party, but what helped me is to set unique x:Name and GroupName over the whole (!) xaml including all the controls in separate files. Maybe it is too strict, but I had two controls in different xamls which had identical Names inside, and once I modified one of them, the later loaded became OK as well.

HTH