【问题标题】:RadioButton Command property not working with xamarin.forms [duplicate]单选按钮命令属性不适用于 xamarin.forms [重复]
【发布时间】:2022-02-11 16:59:06
【问题描述】:

从 Xamarin.Forms 4.7 更新到 Xamarin.Forms 5.0.0.2337 后,RadioButton 命令属性不起作用。在 ViewModel 中使用命令而不是代码隐藏的替代方法是什么。

【问题讨论】:

标签: xamarin.forms mvvm radio-button nuget-update


【解决方案1】:

是的,从 Xamarin.Forms 5.0.0 开始,属性 Command 已从 RadioButton 中删除。

如果您想在状态更改时运行命令,则可以使用事件CheckedChanged

    <RadioButton Content="test">
        <RadioButton.Behaviors>
            <local:EventToCommandBehavior EventName="CheckedChanged" Command="{Binding Source={x:Reference Page}, Path=BindingContext.RadioCommand}"   CommandParameter="V"/>
        </RadioButton.Behaviors>
    </RadioButton>

对于EventToCommandBehavior.cs,您可以参考这里的示例代码:https://github.com/xamarin/xamarin-forms-samples/tree/main/Behaviors/EventToCommandBehavior/EventToCommandBehavior/Behaviors

注意:

Page 是当前页面的x:Name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 2020-06-11
    • 1970-01-01
    • 2012-05-27
    • 1970-01-01
    相关资源
    最近更新 更多