Drag n Drop in Xamarin

Magnus Wallon 0 Reputation points
2024-01-10T09:40:28.7233333+00:00

Hi!

Anyone know if there is some way to speed up the interaction with drag n drop in Xamarin Forms? Im developing a puzzle game for kids and the way it works by default, where you have to hold on the "image" a while before you can start drag it just dont work, nothing kids are used to at all..

Best regards
Magnus

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,651 Reputation points Microsoft Vendor
    2024-01-11T07:30:18.9+00:00

    Hello, I can reproduce this issue in my side. If you want to do real-time drag/drap without delay or long-touch operation, you can do it by SkiaSharp to do it. Before you start it, please install SkiaSharp.Views.Forms and TouchTracking.Forms in your Xamarin.Forms project.

    Then add SKCanvasView in your layout like following code.

    <ContentPage 
                ...
                 xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
                  xmlns:tt="clr-namespace:TouchTracking.Forms;assembly=TouchTracking.Forms"
                ...
    >
    <Grid BackgroundColor="White" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
          <skia:SKCanvasView x:Name="canvasView"
                         PaintSurface="OnCanvasViewPaintSurface" />
          <Grid.Effects>
              <tt:TouchEffect Capture="True"
                          TouchAction="OnTouchEffectAction" />
          </Grid.Effects>
      </Grid>
    

    Then you can add your image to the xxx.Forms folder directly and set the build action to the Embedded resource. For more detailed code, you can refer to this document Dragging and Translation

    Best Regards, Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.