Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGridRow Drag and Drop Visual does not display most of the time #4545

Closed
omnilogix opened this issue Mar 17, 2021 · 4 comments
Closed

DataGridRow Drag and Drop Visual does not display most of the time #4545

omnilogix opened this issue Mar 17, 2021 · 4 comments
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team

Comments

@omnilogix
Copy link

Describe the bug

When performing a Drag and Drop operation with DataGridRow, about 80% of the time the Row visual will not display during dragging. It does not matter whether the visual is specifically set in code, or the default action.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Add a DataGrid with rows on a page:
  2. Enable Drag and Drop for DataGridRows as necessary:
  3. Peform drag operation and observe that the Visual of the row data is often omitted from the drag. Instead you may see the Caption and/or Glyph
private void OnLoadingRow(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridRowEventArgs e)
        {
            e.Row.CanDrag = true;
            e.Row.AllowDrop = true;
            e.Row.DragStarting += Row_DragStarting;
            e.Row.DropCompleted += Row_DropCompleted;
            e.Row.DragEnter += Row_DragEnter;
            e.Row.DragOver += Row_DragOver;
            e.Row.DragLeave += Row_DragLeave;
            e.Row.Drop += Row_Drop;
        }

Optionally, code the visual yourself

private async void Row_DragStarting(UIElement sender, DragStartingEventArgs args)
        {
            args.AllowedOperations = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Move;

            if (sender is DataGridRow row)
            {
                var def = args.GetDeferral();
                var rtb = new RenderTargetBitmap() { };
                await rtb.RenderAsync(row);
                IBuffer pixelBuffer = await rtb.GetPixelsAsync();
                SoftwareBitmap b = SoftwareBitmap.CreateCopyFromBuffer(pixelBuffer, BitmapPixelFormat.Bgra8, (int)rtb.PixelWidth, (int)rtb.PixelHeight);

                args.DragUI.SetContentFromSoftwareBitmap(b, new Point(rtb.PixelWidth / 2, rtb.PixelHeight / 2));
                def.Complete();
            }
        }

Expected behavior
Automatic rendering of the Drag Visual for a DataGridRow

Screenshots

TestDnD

Version Info

NuGet package version:

image

Windows app type:

UWP Win32
YES
Windows 10 version Saw the problem?
Insider Build (xxxxx)
October 2020 Update (19042) YES
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop YES
Xbox
Surface Hub
IoT

Additional context

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 17, 2021
@jschwizer99
Copy link

I observe a similar behavior when starting the drag operation by StartDragAsync. In some cases, the correct behavior is triggered and the element gets moved around. But sometimes I just see the initial DataPackageOperation::None. The events DragStarting and DragOver are triggered correctly. Attaching modifications to DragUIOverride in the DragOver works fine. It is the attachment at drag start which fails. The frequency of the failure is system-dependent, which could point in direction of a race.

@codendone codendone added appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps team-Rendering Issue for the Rendering team product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Mar 18, 2021
@codendone
Copy link
Contributor

We just debugged this issue last week. This is unfortunately a bug in Windows specific to non-UWP apps. It isn't clear right now if we can fix this in WinUI3. On the plus side, this has been fixed in Windows, and is available in current Dev Channel builds from the Windows Insider Program.

@codendone
Copy link
Contributor

Note: In theory it is possible to avoid the issue if you can avoid any awaits (and taking a deferral) in your DragStarting handler. But that likely isn't reasonable for most uses to already have the bitmap ready.

@codendone
Copy link
Contributor

Since #4528 is the same issue, I'm going to close this issue. You can track that one for status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team
Projects
None yet
Development

No branches or pull requests

3 participants