WPF RadioButton selected in UI, but seen by code as IsChecked == false


I have some radio buttons in a group box. I select the buttons randomly, and all works perfectly from a visual standpoint and also the event handler is called each time a new button is selected.

Now I have a dependency property with a callback when the value changes. When in this callback procedure I read the IsChecked value of any button, the value is False, in spite the button is visually selected (they are all false at the same time, strange). The debugger also displays all buttons unchecked.

Hu hu, I'm lacking ideas about the reason, after the basic verifications…

        <RadioButton x:Name="btNone"
        <RadioButton x:Name="btManual"

Event handler:

private void OnSelChecked(object sender, RoutedEventArgs e) {
    if (btManual.IsChecked == true) {
        // is called

Dependency property:

public static readonly DependencyProperty ManualProperty =
            typeof(Position), typeof(SwitchBox),
            new FrameworkPropertyMetadata(null,
                new PropertyChangedCallback(OnManualChanged)));

Dependency property callback:

private static void OnManualChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) {
    SwitchBox box = sender as SwitchBox;
    if (box.btManual.IsChecked == true) {
        // never true, why??

Best Solution

There is a Microsoft bug with the radio button group. If you have multiple instances of the same user control where each user control contains a group of radio buttons, when you change your selection in one instance it will remove the selection from all other instances.

Related Question