MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Dragging from WebView2 to any WPF control doesn't work if a WPF Popup is opened

Open
#2,690 9 comments 0 reactions 2 assignees View on GitHub

@bradp0721 is already working on this.

Since Aug 30, 2023.

bug tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Description
Dragging from WebView2 to any WPF control doesn't work if a WPF Popup is opened

Version
SDK: 1.0.1222-prerelease
Runtime: Evergreen, 104.0.1293.54
Framework: WPF
OS: Win11 21H2 (OS Build 22000, 856)

Repro Steps

  1. Create a sample app with a menu and add the code from additional context to open the popup on DragOver.
  2. Start dragging any element from WebView2 (text, image link, etc.)
  3. Drag that element over the menu to make the submenu open
  4. Drop the element

Expected:

  • Element is dropped and Drop event arrives in menu

Actual:

  • Drag operation is stuck and the popup stays open until the drag operation is cancelled by pressing Escape.
  • If another drag operation is called using DragDrop.DoDragDrop then COMException with A drag operation is already in progress message.

Screenshots
drag-drop-bug

Additional context
The same steps work fine when dragging things from Edge / Chrome which makes me think this is a WebView2 bug, not a WPF bug.

The following code was used with WebView2WpfBrowser in WebView2Samples project:

        private void Menu_DragOver(object sender, DragEventArgs e)
        {
            e.Effects = e.AllowedEffects;
            e.Handled = true;

            if (sender is UIElement uiElement)
            {
                var position = e.GetPosition(uiElement);
                var result = VisualTreeHelper.HitTest(uiElement, position);
                var menuItem = FindVisualParent<MenuItem>(result?.VisualHit);
                if (menuItem?.HasItems == true)
                {
                    menuItem.IsSubmenuOpen = true;
                }
            }
        }

        private void Menu_Drop(object sender, DragEventArgs e)
        {
            e.Handled = true;

            MessageBox.Show(this, $"'{e.Data.GetData(DataFormats.UnicodeText)}' dropped");
        }

        public static T FindVisualParent<T>(DependencyObject element)
            where T : DependencyObject =>
            element == null ? null : element as T ?? FindVisualParent<T>(VisualTreeHelper.GetParent(element));

AB#46318657

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.