I have a custom picker. I need to call an API on selection changed of the picker and the implementation must be only in MVVM. DistanceDropdown is the x:Name of picker.
<custom:MyPicker.Behaviors>
<behaviors:EventToCommandBehavior EventName="SelectedIndexChanged"
Command="{Binding Path=BindingContext.DistanceChangedCommand,Source={x:Reference DistanceDropdown}}"></behaviors:EventToCommandBehavior>
</ccustom:MyPicker.Behaviors>
And DistanceChangedCommand has a method
DistanceChangedCommand = new Command<object>(async (x) => await DistanceChangedAction(x as SelectionChangedEventArgs));
The method gets hit, but the args are null
private async Task DistanceChangedAction(SelectionChangedEventArgs selectionChangedEventArgs)
{
await Task.CompletedTask;
}
What am I going wrong? I have also tried with CommandParameter={Binding}
.