WPF单选按钮上的奇怪聚焦矩形

7
为什么当单选按钮被点击时,矩形会出现在其上?
下面是XAML标记:

strange focus rectangles on wpf radiobutton

<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>
3个回答

26

我本来返回的是null,应该返回Binding.Donothing。

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return (bool)value ? Enum.Parse(targetType, parameter.ToString(), true) : Binding.DoNothing;
            }

布尔值。什么也不做...真棒的答案! - aromore

5
那些被称为FocusVisualStyle,你可以将其移除 -
<RadioButton FocusVisualStyle="{x:Null}"/>

更新

是的,H.B.说得对,我以为你在谈论我们在单击单选按钮时看到的点状边框。但这似乎是一个验证边框,请检查您的转换器代码,其中某些内容可能已经损坏。


+1 虽然这不是回答这个问题的方法,但每个人都应该知道如何禁用FocusVisuals,因为如果你不知道要查找什么,它们可能很难找到。 - erodewald

2

在我看来,这似乎是一个验证错误,可能是因为ConverterParameter前面的空格造成的。(您可能需要考虑使用其他方法来绑定RadioButtons)


@TrustyCoder:那又怎样?无论错误来自何处(在这种情况下应该是转换器抛出异常),它仍然是一个验证错误。 - H.B.
@TrustyCoder,@H.B. 正在谈论此块中的空格:ConverterParameter= LabOnly。这将传递一个类似于 " LabOnly" 的字符串,由于某种原因可能会将其标记为无效。 - erodewald
不,我猜那不是原因。当我移除转换器表达式后,它就正常了。所以我认为枚举到布尔型转换器出了问题。 - TrustyCoder
@TrustyCoder:嗯?那就是我刚才说的。此外,转换器可能很好,但如果传入一个带有空格的字符串,它可能会抛出异常。正如我所说:首先不要使用转换器,请参见我的答案中的链接。 - H.B.
我有两个枚举和两个单选按钮组。但是在一切相同的情况下,一个验证错误和一个成功(WTF)。 - Trương Quốc Khánh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接