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
- 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.
<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> |
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}"); } } |
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); } } |
SfListView, please refer the following UG and KB articles:Attachment: ListViewSample198136_e4bc7999.zip
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**
- 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.
- Single-click an item → Wait 300ms → Only [Single Tap] fires
- Double-click an item → Immediately only [Double Tap] fires (no single-click)
Attachment: ListViewSample198136_9823b262.zip
Goodmorning,
Works like charm.
Thank you.
Muthu Kumar Madasamy
- 5 Replies
- 2 Participants
-
TV Thijs van Rijswijk
- Feb 23, 2026 07:03 AM UTC
- Mar 2, 2026 01:01 PM UTC