7

Why does the rectangle appear in the radio buttons when one of them is clicked.

strange focus rectangles on wpf radiobutton

the XAML markup is given below

<RadioButton GroupName="LabelDisp" IsChecked=".. Converter={StaticResource enumBooleanConverter}, ConverterParameter= LabOnly}" Content="{x:Static resx:StringRes.RadioButtonLab}" Style="{StaticResource ListOption}" Command="{Binding Path=Command}"></RadioButton>
<RadioButton GroupName="LabelDisp" IsChecked=".. Converter={StaticResource enumBooleanConverter}, ConverterParameter= DescOnly}" Content="{x:Static resx:StringRes.RadioButtonDesc}" Style="{StaticResource ListOption}" Command="{Binding Path=Command}"></RadioButton>
<RadioButton GroupName="LabelDisp" IsChecked=".. Converter={StaticResource enumBooleanConverter}, ConverterParameter= LabAndDescr}" Content="{x:Static resx:StringRes.RadioButtonBoth}" Style="{StaticResource ListOption}" Command="{Binding Path=Command}"></RadioButton>
H.B.
  • 166,899
  • 29
  • 327
  • 400
TrustyCoder
  • 4,749
  • 10
  • 66
  • 119

3 Answers3

26

I was returning null should have returned Binding.Donothing instead.

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return (bool)value ? Enum.Parse(targetType, parameter.ToString(), true) : Binding.DoNothing;
            }
TrustyCoder
  • 4,749
  • 10
  • 66
  • 119
5

Those are called FocusVisualStyle, you can remove it -

<RadioButton FocusVisualStyle="{x:Null}"/>

Update

Yeah H.B. is right, i thought you was talking about dotted border we got on clicking radioButton. But it seems a validation border, check your converter code, something is breaking in it.

Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • +1 While not the answer to this question, everybody should know how to disable FocusVisuals, since they can be difficult to find if you don't know what to look for. – erodewald Aug 15 '12 at 18:53
2

Looks like a validation error to me, possibly because of the spaces at the front of the ConverterParameter. (You might want to consider using another method for binding RadioButtons)

Community
  • 1
  • 1
H.B.
  • 166,899
  • 29
  • 327
  • 400
  • @TrustyCoder: So? It's still a validation error, no matter where it comes from (it should be the converter throwing an exception in this case) – H.B. Aug 15 '12 at 15:17
  • @TrustyCoder, @H.B. was talking about the space in this block: `ConverterParameter= LabOnly`. This is passing in a string like this: `" LabOnly"`, which might be marking it as invalid for whatever reason. – erodewald Aug 15 '12 at 18:52
  • no that is not the reason i guess. when i removed the converter expression its fine. so i am assuming something is wrong with the enum to boolean converter. – TrustyCoder Aug 15 '12 at 20:23
  • @TrustyCoder: Huh? That's what i just said. Also the converter could possibly be fine but if you pass in a string with a space it might throw an exception. Also as i said: Don't use a converter in the first place, see the link in my answer. – H.B. Aug 15 '12 at 20:57
  • I have two enum and two group radio. But one validation error and one success while everything same ( WTF ) – Trương Quốc Khánh Feb 21 '22 at 03:45