xamarin.formsmvvmradio-buttonnuget-update

RadioButton Command property not working with xamarin.forms


RadioButton command property not working after updated from Xamarin.Forms 4.7 to Xamarin.Forms 5.0.0.2337. what are the alternative ways to use command in ViewModel not with codebehind.


Solution

  • Yes,since Xamarin.Forms 5.0.0, the property Command has been removed from RadioButton.

    If you want to run a command upon state change then you can use the event CheckedChanged.

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

    For EventToCommandBehavior.cs, you can refer sample code here: https://github.com/xamarin/xamarin-forms-samples/tree/main/Behaviors/EventToCommandBehavior/EventToCommandBehavior/Behaviors .

    Note:

    Page is the x:Name of current page.