RadioButton Command属性不适用于xamarin.forms



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

是的,自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

最新更新