PointerGestureRecognizer

Good morning,

Is it possible to create an example of a PointerGestureRecognizer? I would like to know how I can handle both a single and a double mouse click in MVVM. I’ve tried using behaviors, but I can’t get it to work. Could you point me in the right direction?

Thank you in advance.


Thijs van Rijswijk


5 Replies

MM Muthukumar Madasamy Syncfusion Team February 24, 2026 10:38 AM UTC

Hi Thijs van Rijswijk,

Thanks for contacting us and for sharing the detailed requirement.

You can handle both single and double mouse clicks in SfListView using MVVM without PointerGestureRecognizer by:

  • Using TapCommand for single click/tap.
  • Using the ItemDoubleTapped event with a small behavior that converts the event into a command for double click/double tap.
Below are the key parts of the implementation. We have also attached a simple sample for your reference.

1. XAML – single tap + behavior for double tap

<syncfusion:SfListView
    x:Name="listView"
    ItemsSource="{Binding Mails}"
    AutoFitMode="Height"
    SelectionMode="None"
    <!-- Single click / tap -->
    TapCommand="{Binding SingleClickCommand}">

    <!-- Double click / double tap via behavior -->
    <syncfusion:SfListView.Behaviors>
        <local:EventToCommandBehavior
            Command="{Binding DoubleClickCommand}" />
    </syncfusion:SfListView.Behaviors>

    <!-- ItemTemplate omitted for brevity -->
</syncfusion:SfListView>


2. ViewModel – single & double click commands

public class MailViewModel
{
    public ObservableCollection<MailInfo> Mails { get; set; }

    public ICommand SingleClickCommand { get; }
    public ICommand DoubleClickCommand { get; }

    public MailViewModel()
    {
        // Initialize Mails...

        SingleClickCommand = new Command<ItemTappedEventArgs>(OnItemTapped);
        DoubleClickCommand = new Command<ItemDoubleTappedEventArgs>(OnItemDoubleTapped);
    }

    private void OnItemTapped(ItemTappedEventArgs args)
    {
        if (args?.DataItem is not MailInfo mail)
            return;

        // Single-click logic
        System.Diagnostics.Debug.WriteLine($"[Single Tap] {mail.Subject}");
    }

    private void OnItemDoubleTapped(ItemDoubleTappedEventArgs args)
    {
        if (args?.DataItem is not MailInfo mail)
            return;

        // Double-click logic
        System.Diagnostics.Debug.WriteLine($"[Double Tap] {mail.Subject}");
    }
}

3. Behavior – convert ItemDoubleTapped to command

public class EventToCommandBehavior : Behavior<SfListView>
{
    public static readonly BindableProperty CommandProperty =
        BindableProperty.Create(
            nameof(Command),
            typeof(ICommand),
            typeof(EventToCommandBehavior),
            null);

    public ICommand Command
    {
        get => (ICommand)GetValue(CommandProperty);
        set => SetValue(CommandProperty, value);
    }

    SfListView _associatedObject;

    protected override void OnAttachedTo(SfListView bindable)
    {
        base.OnAttachedTo(bindable);

        _associatedObject = bindable;

        // Sync BindingContext with SfListView
        _associatedObject.BindingContextChanged += OnListViewBindingContextChanged;
        BindingContext = _associatedObject.BindingContext;

        _associatedObject.ItemDoubleTapped += OnItemDoubleTapped;
    }

    protected override void OnDetachingFrom(SfListView bindable)
    {
        base.OnDetachingFrom(bindable);

        if (_associatedObject != null)
        {
            _associatedObject.BindingContextChanged -= OnListViewBindingContextChanged;
            _associatedObject.ItemDoubleTapped      -= OnItemDoubleTapped;
            _associatedObject = null;
        }
    }

    void OnListViewBindingContextChanged(object sender, EventArgs e)
        => BindingContext = _associatedObject?.BindingContext;

    void OnItemDoubleTapped(object sender, ItemDoubleTappedEventArgs e)
    {
        if (Command == null)
            return;

        if (Command.CanExecute(e))
            Command.Execute(e);
    }
}

For more information about handling taps and converting events to commands in SfListView, please refer the following UG and KB articles:


We have attached a simple working sample demonstrating this behavior for your reference. Please check it and let us know if you need any further assistance.

Best Regards,
Muthu Kumar Madasamy.

Attachment: ListViewSample198136_e4bc7999.zip


TV Thijs van Rijswijk February 25, 2026 05:51 AM UTC

Good morning, 

It’s almost what I wanted, so thank you for that.

The only thing that still happens is that the SingleClick fires before the DoubleClick, and I would like to have only one of the two.

This is because it first executes the SingleClick code and only then the DoubleClick.


SingleClick result:

[Single Tap] Giso van Veldhuizen


DoubleClick result:

[Single Tap] Giso van Veldhuizen

[Double Tap] Giso van Veldhuizen


As you can see, the SingleClick always triggers, while I would prefer to have only one event.

So if there is a DoubleClick, then only that event should fire, without the SingleClick coming through.

In any case, thank you for the effort, and if this works, I can move on to .NET 10.


Kind regards,

Thijs van Rijswijk**



MM Muthukumar Madasamy Syncfusion Team February 25, 2026 12:45 PM UTC

Hi Thijs van Rijswijk,

Thank you for your follow-up and for providing the detailed feedback.

You're absolutely correct about the issue you observed is expected behavior because a double-click naturally consists of two single clicks in rapid succession. By default, the TapCommand fires on the first click, which is why the single-click event triggers before the double-click.

Workaround:
To achieve the behavior you requested (only one event firing either single-click OR double-click, but not both), we've implemented a timer-based delay mechanism in the ViewModel:

  • Single-Click: A 300ms timer starts when you click. If no second click occurs within that time, the single-click action executes.
  • Double-Click: The pending single-click timer is immediately canceled, and only the double-click action executes.

Result:
  • Single-click an item → Wait 300ms → Only [Single Tap] fires
  • Double-click an item → Immediately only [Double Tap] fires (no single-click)

The 300ms delay is a standard Windows UI pattern, but you can adjust it by modifying the ClickDelay constant if needed.

We have attached the updated sample demonstrating this behavior for your reference. Please test it and let us know if this meets your requirements.

Best Regards,
Muthu Kumar Madasamy

Attachment: ListViewSample198136_9823b262.zip


TV Thijs van Rijswijk replied to Muthukumar Madasamy March 2, 2026 05:14 AM UTC

Goodmorning,


Works like charm.


Thank you.



MM Muthukumar Madasamy Syncfusion Team March 2, 2026 01:01 PM UTC

Hi Thijs,

We are glad to hear that the updated solution is working perfectly on your end. 🎉

If you need any further assistance or have more questions, feel free to reach out. We’re always happy to help!

Best Regards,
Muthu Kumar Madasamy

Loader.
Up arrow icon