microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Drag Drop outside window broken with 1.5-preview1

Open stevenbrix opened this issue 1 year ago • 3 comments

Describe the bug

When a user drags outside of our app, we create a transparent window which follows the mouse pointer and is used to allow people to drag tabs to a new window. This worked well in 1.4, but is now broken in 1.5 preview. The simple act of creating a window (doesn't even need to be shown) breaks the app

Steps to reproduce the bug

  1. Create new winui3 project
  2. Replace MainWindow.xaml with:
<Window
    x:Class="WinUI3Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinUI3Test"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Black">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock Text="DragMe" CanDrag="True" DragStarting="TextBlock_DragStarting"/>
        </StackPanel>
    </Grid>

</Window>
  1. Replace MainWindow.xaml.cs with:
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            Content.DragLeave += Content_DragLeave;
            Content.DragOver += Content_DragOver;
            Content.AllowDrop = true;
        }

        private void Content_DragOver(object sender, DragEventArgs e)
        {
            e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
        }

        private Window placeholderWindow;
        private void Content_DragLeave(object sender, DragEventArgs e)
        {
            if (placeholderWindow == null) {
                placeholderWindow = new Window();
            }
        }

        private void TextBlock_DragStarting(UIElement sender, DragStartingEventArgs args)
        {
            args.AllowedOperations = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
        }
    }
4. F5 the app
5. Drag the text block labeled "Drag Me" outside of the window

Expected behavior

I can continue the drag operation

Screenshots

https://github.com/microsoft/microsoft-ui-xaml/assets/9649518/cfda6bd3-997c-4576-9631-998c3ad35283

NuGet package version

WinUI 3 - Windows App SDK 1.5 Preview 1: 1.5.240205001-preview1

Windows version

Windows 11 (22H2): Build 22621

Additional context

It's the simple act of creating the window that causes things to stop working. If you comment out placeholderWindow = new Window(); then the drag continues to work

stevenbrix avatar Feb 23 '24 19:02 stevenbrix

some more context, while more inconsistent, i can repro this bug without having to leave the bounds of the window.

https://github.com/microsoft/microsoft-ui-xaml/assets/9649518/477c6d85-a083-42a3-bc8a-37934eb13bd5

here's the updated MainWindow.xaml.cs for this:

    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            Content.DragLeave += Content_DragLeave;
            Content.DragOver += Content_DragOver;
            Content.AllowDrop = true;
            Content.Drop += Content_Drop;
        }

        private void Content_Drop(object sender, DragEventArgs e)
        {
            placeholderWindow = null;
        }

        private void Content_DragOver(object sender, DragEventArgs e)
        {
            e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
        }

        private Window placeholderWindow;
        private void Content_DragLeave(object sender, DragEventArgs e)
        {
            if (placeholderWindow == null) {
               placeholderWindow = new Window();
            }
        }

        private void TextBlock_DragStarting(UIElement sender, DragStartingEventArgs args)
        {
            args.AllowedOperations = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
            if (placeholderWindow == null) {
                placeholderWindow = new Window();
            }
        }

    }

EDIT: this repro only seems to be caused by the in-app toolbar

stevenbrix avatar Feb 23 '24 23:02 stevenbrix

If you disable the 'In-app Toolbar' it doesn't seem to repro. Probably related to #8806 which is reported as fixed in 1.5 release candidate (not available yet).

kmgallahan avatar Feb 25 '24 15:02 kmgallahan

that only seems to affect the second repro i gave. the first one still reproes without the in app toolbar. we see this in our app and we don't us VS for debugging

stevenbrix avatar Feb 26 '24 19:02 stevenbrix

@JochemPalmsens, does that mean it is fixed in 1.5 or it still repros in 1.5? From the earlier comments, it appears to be a dup of the in-app toolbar, but those should be fixed (betwwen 1.5 and VS 17.9).

bpulliam avatar Mar 04 '24 23:03 bpulliam

@bpulliam sorry for the confusion. I just wanted to inform the OP that a new version was out.

Now I took the responsibility to test this. No it's not fixed. The in-app toolbar bug was also a bug in 1.4. This is a bug in 1.5

I have made a small test project with identical code (as described in the opening post) and 3 versions of winappsdk: 1.4.240211001, 1.5.240205001-preview1 and 1.5.240227000 With both 1.5 versions the dragged icon "locks up" as soon as I drag it out of the window: image

So the bug is still in the release of 1.5.

(Disclaimer: I do not take ownership of the code from the OP: I don't know if they are doing something "wrong" that by coincidence worked in 1.4).

JochemPalmsens avatar Mar 05 '24 08:03 JochemPalmsens

@bpulliam this is not a dupe of the in-app toolbar. we just tested and this issue is not fixed in the latest 1.5 even with the in-app toolbar disabled

stevenbrix avatar Mar 18 '24 22:03 stevenbrix

Our team seems to hit this issue too. Our app is on version 1.5.240311000. Some examples of Drag&Drop use in our case:

  • Not working anymore when dragging from our app to Desktop, Outlook, or File Explorer
  • Still working when dragging from our app to Teams chat, OneNote Online page, or Clipchamp

alcail avatar Apr 18 '24 20:04 alcail

The fix is now also in Version 1.5.4 (1.5.240607001).

codendone avatar Jun 12 '24 00:06 codendone