Execute ICommand when an event fires in UI Controls.
For example, ItemTapped event of ListView does not provide a property to bind Command.
The following code executes ICommand when firing the Itemtapped event.
<ListView ItemsSource="{Binding Fruits}">
<ListView.Behaviors>
<behaviorsPack:EventToCommandBehavior
EventName="ItemTapped"
Command="{Binding SelectedFruitCommand}"/>
</ListView.Behaviors>
You can also pass any property of EventArgs to the ICommand by specifying the event's properties.
ItemTappedEventArgs is fired when the ListView's ItemTapped event occurs.
ItemTappedEventArgs has Item property that holds the tapped item.
Therefore, by specifying EventArgsPropertyPath, it is possible to pass tapped objects to ICommand.
<ListView ItemsSource="{Binding Fruits}">
<ListView.Behaviors>
<behaviorsPack:EventToCommandBehavior
EventName="ItemTapped"
Command="{Binding SelectedFruitCommand}"
EventArgsPropertyPath="Item"/>
</ListView.Behaviors>
public ICommand SelectedFruitCommand => new Command<Fruit>(fruits =>
{
...
});