Search code examples
windowsuwpdrag-and-droplag

drag and drop - lag in UWP


Hello drag and drop fans,

Can anyone explain why I see a long lag time when using drag and drop with my UWP apps?

I wrote a test app that contains just the drag and drop message handlers and also the pointer handlers for comparison. Here’s the code...

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();

        grid1.AllowDrop = true;
        grid1.DragOver += Grid1_DragOver;
        grid1.Drop += Grid1_Drop;
        grid1.DragLeave += Grid1_DragLeave;

        grid1.PointerEntered += Grid1_PointerEntered;
        grid1.PointerExited += Grid1_PointerExited;

    }

    //  Drag Handlers ************************
    private void Grid1_DragOver(object sender, DragEventArgs e)
    {
        msgFromPointer.Text = "  drag/drop item has entered";

        e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
        Debug.WriteLine("in grid1 drag over handler");
    }

    private void Grid1_DragLeave(object sender, DragEventArgs e)
    {
        msgFromPointer.Text = "";
    }

    private void Grid1_Drop(object sender, DragEventArgs e)
    {
        Debug.WriteLine("in grid1 drop handler");
    }


    // pointer handlers *******************
    private void Grid1_PointerEntered(object sender, PointerRoutedEventArgs e)
    {

        msgFromPointer.Text = "POINTER has entered";
    }

    private void Grid1_PointerExited(object sender, PointerRoutedEventArgs e)
    {
        msgFromPointer.Text = "";
    }

When doing a drag and drop to my app, there seems to be about a 1/2 second delay before my app receives the dragOver message. In comparison, the pointerOver message seems to arrive almost simultaneously with the pointer movement. The slow behavior is the same when using the touch screen or a mouse. Here’s a video of the behavior…

video of the laggy behavior

The PC I’m using has a touch screen and I’m wondering if there is some sort of touch “driver” or filter that is slowing down the drag and drop message. I've tried a bunch of Windows config settings, like mouse and display settings, but no change. The PC is a Dell Inspiron 3593, with the latest drivers. My Windows 10 version is 1903, build 18362.836

The app I’m developing uses a lot of drag and drop and this slow behavior makes the user interface really difficult. It’s kind of like trying to conduct a phone conversation with a 1/2 second delay.

Any ideas?

Dan


Solution

  • The DragOver event is triggered when the application determines that the element under the current pointer is a potential placement target.

    This requires the pointer to hover for a period of time. This may be the reason for the delay you think.

    You can try the DragEnter event, which is triggered earlier than DragOver.

    Thanks