microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 678 forks source link

Cannot set DragUI visual. #10144

Open Gavin-Williams opened 1 week ago

Gavin-Williams commented 1 week ago

Describe the bug

When I set the visual for a drag and drop operation using...

args.DragUI.SetContentFromBitmapImage(bmp);

The image is not visible.

Steps to reproduce the bug

  1. Create a handler for DragStarting
  2. Provide a BitmapImage as a source image
  3. Set the visual.

Expected behavior

I expect to see the image.

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.6.1: 1.6.240923002

Windows version

Windows 11 (22H2): Build 22621

Additional context

DragUI.SetContentFromSoftwareBitmap() does not show the bitmap #4528

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

castorix commented 1 week ago

I works on my Windows 10 22H2 OS, Windows App SDK 1.6.240829007 :

    private void Img1_DragStarting(UIElement sender, DragStartingEventArgs args)
    {
        args.AllowedOperations = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
        args.DragUI.SetContentFromBitmapImage(new BitmapImage(new Uri("ms-appx:///Assets/ButterflyBlue_small.png", UriKind.RelativeOrAbsolute)));
    }

Image

Gavin-Williams commented 1 week ago

@castorix that works for me too. Ok, I've found the case where it doesn't work, and maybe there's something I don't understand about WinUI. If I use the BitmapImage beforehand as a source for another Image control, it doesn't work.

TestImage.Source = GlobalBitmapImage; // I see this.
args.DragUI.SetContentFromBitmapImage(GlobalBitmapImage); // I don't see this

Copilot and other resources say that I can use BitmapImage as a source for multiple items.