【问题标题】:Binding to RadioButtons IsChecked gets cleared after uncheking取消选中后,绑定到单选按钮 IsChecked 被清除
【发布时间】:2010-05-13 16:11:57
【问题描述】:

我有一个 radioButton 组,每个 Button 都绑定到一个 Enum 属性

<RadioButton Name="rbFixedDiscount" IsChecked="{Binding Path=DiscountType, Mode=TwoWay, Converter={StaticResource EnumConverter},ConverterParameter=Fixed, UpdateSourceTrigger=PropertyChanged}" >Fixed:</RadioButton>

<RadioButton Name="rbPercentDiscount" Grid.Row="1" IsChecked="{Binding Path=DiscountType, Mode=TwoWay, Converter={StaticResource EnumConverter},ConverterParameter=Percent, UpdateSourceTrigger=PropertyChanged}">Percent:</RadioButton>

<RadioButton Name="rbFreeNightsDiscount" Grid.Row="2" IsChecked="{Binding Path=DiscountType, Mode=TwoWay, Converter={StaticResource EnumConverter},ConverterParameter=FreeNights, UpdateSourceTrigger=PropertyChanged}">Free Nights:</RadioButton>

每当我在 UI 中来回单击时,只有在单击新 RB 时才会更新后面的属性,如果我单击返回的按钮之一(所以我将其设为选中 -> 未选中 -> 选中)后面的属性绑定不刷新,它的绑定已被清除我认为这是因为在取消选中和 Item.ClearValue() 时会调用 ClearValue()。 无论如何,我可以在来回单击时保持绑定。

【问题讨论】:

    标签: wpf data-binding xaml wpf-controls


    【解决方案1】:

    这是一个带有单选按钮的known and annoying bug。幸运的是,有一些解决方法,以下是我见过的一些:

    1. 将列表框重新设置为单选按钮并改用它。
    2. 在控件模板中声明绑定。 (link)
    3. 将每个单选按钮放在不同的组中,并通过值转换器控制它们的选中/未选中属性。 (link)

    希望其中一种解决方案对您有用!

    【讨论】:

    • 似乎已在 .NET 4.0 中修复。
    猜你喜欢
    • 2013-06-06
    • 2016-04-10
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多