Unlike other MVVM libraries we do not have a EventToCommand class. We use a short and more convenient way to bind events to commands.
Lets bind the Tapped event to a command in XAML:
<TextBlock Mvvm:EventBinding.Tapped="{Binding TappedCommand}" Text="Tap me"/>
Here is an example of a view model class with a command that handles an event from the UI:
public class SimpleViewModel
{
public SimpleViewModel()
{
TappedCommand = new EventCommand<Point>(OnTapped);
}
public IEventCommand TappedCommand { get; private set; }
private void OnTapped(Point point)
{
// You can mark the event as handled by using the PreventBubbling property.
// This property value will not be reset automatically.
// So you can set it once in the constructor or update it anywhere.
TappedCommand.PreventBubbling = point.X < 100;
}
}