1
votes

In an item control i have dynamically binding the list of Radio button. Each of the radio button having the binding with the 'IsChecked' and 'Group' from View Model.

In some certain scenarios from the db level, Ischecked is coming as true for multiple radio buttons in the same group. In that case, all radio button in the same group got checked. it is not unchecking other radio buttons when other radio checked through binding.

<ItemsControl DataContext="{Binding}" ItemsSource="{Binding TabsList,UpdateSourceTrigger=PropertyChanged}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ContentControl Margin="5">
                        <RadioButton GroupName="test" IsChecked="{Binding Checked}" Content="{Binding _Header}"></RadioButton>                     
                    </ContentControl >
                </DataTemplate>
            </ItemsControl.ItemTemplate>          
        </ItemsControl>

Its working fine if i manually checking after the binding.

Thanks in advance for the response.

1

1 Answers

1
votes

Your issue is caused by the order that RadioButton properties are set.

In this case (similar to your case):

<RadioButton IsChecked="{Binding IsChecked1}" GroupName="{Binding GroupName}" />
<RadioButton IsChecked="{Binding IsChecked2}" GroupName="{Binding GroupName}" />

the binding for the IsChecked property is invoked before the binding of the GroupName property. So when the IsChecked property is set, the GroupName property which belongs to the same RadioButton is still unset. It means that the GroupName mechanism cannot be applied.

Just reverse the order which you declare those two properties in:

<RadioButton GroupName="{Binding GroupName}" IsChecked="{Binding IsChecked1}" />
<RadioButton GroupName="{Binding GroupName}" IsChecked="{Binding IsChecked2}" />

and everything will work fine, since when the IsChecked propery is set, the RadioButton already knows which its group name is.

I hope it helps.