CellDoubleTap and CellTap Commands

1 Answer 20 Views
DataGrid
n/a
Top achievements
Rank 1
Iron
n/a asked on 05 Jan 2024, 09:47 AM

I need to differentiate between CellTap and CellDoubleTap commands.
I registered both commands:

 DataGrid.Commands.Add(new CellDoubleTapUserCommand());
 DataGrid.Commands.Add(new CellTapUserCommand());

But when I double tap cell, the CellTap command is also fired.
Is there any out of the box solution fo this?

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 05 Jan 2024, 12:09 PM

Hi,

In the DataGrid commands flow, Double tap is two times tap. So tap is executed also on double tap. 

You can extend the logic in the commands and add a flag. Change its value to true on double tap. Also inside the dispatcher add a check for tap. Here is the implementation:

    public class CellTapUserCommand : DataGridCommand
    {
        public CellTapUserCommand()
        {
            Id = DataGridCommandId.CellTap;
        }
        public override bool CanExecute(object parameter)
        {
            return true;
        }
        public override void Execute(object parameter)
        {
            var info = (DataGridCellInfo)parameter;

            Device.StartTimer(TimeSpan.FromMilliseconds(150), () =>
            {
                if (!CellDoubleTapUserCommand.isDoubleTap)
                {
                    this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CellTap, parameter);
                    Debug.WriteLine("Cell tap is executed");

                }
                else
                {
                    CellDoubleTapUserCommand.isDoubleTap = false;
                }

                return false;
            });

        }
    }
    public class CellDoubleTapUserCommand : DataGridCommand
    {
        internal static bool isDoubleTap;

        public CellDoubleTapUserCommand()
        {
            Id = DataGridCommandId.CellDoubleTap;
        }
        public override bool CanExecute(object parameter)
        {
            return true;
        }
        public override void Execute(object parameter)
        {
            isDoubleTap = true;
            this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CellDoubleTap, parameter);
            Debug.WriteLine("Cell double tap is executed");
        }
    }

 

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

n/a
Top achievements
Rank 1
Iron
commented on 11 Jan 2024, 03:22 PM

I thougth that timer is the only way to do this and I do this in that way.
Thanks for answer.
Tags
DataGrid
Asked by
n/a
Top achievements
Rank 1
Iron
Answers by
Didi
Telerik team
Share this question
or