0

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

4

1 回答 1

2

是的,从 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 。

笔记:

Pagex:Name当前页面的。

于 2022-02-11T08:59:06.230 回答