【问题标题】:strange focus rectangles on wpf radiobuttonwpf单选按钮上奇怪的焦点矩形
【发布时间】:2012-08-11 20:56:18
【问题描述】:

当单选按钮中的一个被单击时,为什么矩形会出现在单选按钮中。

XAML 标记如下所示

<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>

【问题讨论】:

    标签: wpf xaml radio-button


    【解决方案1】:

    我返回 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;
                }
    

    【讨论】:

    • Boolean.DoNothing...很好的答案!
    【解决方案2】:

    那些叫做 FocusVisualStyle,你可以去掉它-

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

    更新

    是的,H.B.是的,我以为你在谈论我们在单击单选按钮时得到的虚线边框。但它似乎是一个validation border,请检查您的转换器代码,其中有问题。

    【讨论】:

    • +1 虽然不是这个问题的答案,但每个人都应该知道如何禁用 FocusVisuals,因为如果您不知道要寻找什么,就很难找到它们。
    【解决方案3】:

    对我来说看起来像是一个验证错误,可能是因为 ConverterParameter 前面的空格。 (您可能要考虑使用another method 来绑定 RadioButtons)

    【讨论】:

    • @TrustyCoder:所以?它仍然是一个验证错误,无论它来自哪里(在这种情况下应该是转换器抛出异常)
    • @TrustyCoder, @H.B.正在谈论这个街区的空间:ConverterParameter= LabOnly。这是在传递一个像这样的字符串:" LabOnly",无论出于何种原因,它都可能将其标记为无效。
    • 不,这不是我猜的原因。当我删除转换器表达式时,它很好。所以我假设枚举到布尔转换器有问题。
    • @TrustyCoder:嗯?这就是我刚才所说的。转换器也可能没问题,但如果你传入一个带空格的字符串,它可能会引发异常。同样正如我所说:首先不要使用转换器,请参阅我的答案中的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2013-05-18
    • 2014-09-20
    相关资源
    最近更新 更多