strange focus rectangles on wpf radiobutton
Asked Answered
T

3

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>
Tillie answered 15/8, 2012 at 14:40 Comment(0)
T
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;
            }
Tillie answered 16/10, 2012 at 17:3 Comment(1)
Boolean.DoNothing...great answer!Stove
S
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.

Schofield answered 15/8, 2012 at 14:41 Comment(1)
+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.Imprimis
D
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)

Doubletime answered 15/8, 2012 at 14:43 Comment(5)
@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)Doubletime
@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.Imprimis
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.Tillie
@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.Doubletime
I have two enum and two group radio. But one validation error and one success while everything same ( WTF )Wort

© 2022 - 2024 — McMap. All rights reserved.