0

I am using xamarin community toolkit for LongPress and GestureRecognizers for PinchGestureRecognizer. After the completion of PinchGestureRecognizer, xct:TouchEffect.LongPressCommand is also fired. Is there any way to trigger these events once at a time?

Here is my code sample

 <StackLayout
        xct:TouchEffect.LongPressCommand="{Binding LongPressCommand}"
        xct:TouchEffect.LongPressCommandParameter="LongPress"
        BackgroundColor="Red">
        <Frame
            Padding="24"
            BackgroundColor="#2196F3"
            CornerRadius="0">
            <Label
                FontSize="36"
                HorizontalTextAlignment="Center"
                Text="Welcome to Xamarin.Forms!"
                TextColor="White" />
        </Frame>
        <Label
            Padding="30,10,30,10"
            FontSize="Title"
            Text="Start developing now" />
        <Label
            Padding="30,0,30,0"
            FontSize="16"
            Text="Make changes to your XAML file and save to see your UI update in the running app with XAML Hot Reload. Give it a try!" />
        <Label Padding="30,24,30,0" FontSize="16">
            <Label.FormattedText>
                <FormattedString>
                    <FormattedString.Spans>
                        <Span Text="Learn more at " />
                        <Span FontAttributes="Bold" Text="https://aka.ms/xamarin-quickstart" />
                    </FormattedString.Spans>
                </FormattedString>
            </Label.FormattedText>
        </Label>
        <StackLayout.GestureRecognizers>
            <PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
        </StackLayout.GestureRecognizers>
    </StackLayout>

The cs file

        public ICommand LongPressCommand { get; set; }
        public MainPage()
        {
           
            InitializeComponent();           
            LongPressCommand = new Command<string>(LongPress);
            BindingContext = this;
        }
        public void LongPress(string flag)
        {
        }
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            
        }
    }
Santos
  • 66
  • 7
  • 1
    You might need to save current time during `OnPinchUpdated`. Then in `LongPress`, check how much time has passed since the most recent `OnPinchUpdated`. If the time passed is "too short" (maybe 250 msec? experiment with different values), then ignore that `LongPress`. – ToolmakerSteve Oct 31 '22 at 22:21

1 Answers1

0

You can set a duration of the LongPress command to trigger the command. The default is 500ms, you can set it via LongPressDuration property. In the example below, I set it to 3s which means the LongPress will be triggered after 3s . You can set the proper duration to avoid the conflict with PinchGestureRecognizer.

xct:TouchEffect.LongPressDuration="3000"
Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15