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;

Lets bind it to the Tapped event in XAML:

<Grid Mvvm:EventBinding.Tapped="{Binding TappedCommand}">
    <!-- Your content goes here -->

Last edited Sep 20, 2012 at 3:38 AM by mglukhankov, version 2


No comments yet.