Canvas not allowing Drag and Drop

I have a Canvas on a Window on a Desktop App on a Mac

Xojo Version 2024.2.1 MacOS Version 14.7.1 Sonomo

Open Event:
Me.AcceptPictureDrop
Me.AcceptFileDrop(“image/png”)
Me.AcceptFileDrop(“image/jpeg”)

DropObject Event:
If obj.PictureAvailable Then
imgDropPic = obj.Picture
End If
Me.Refresh
Return

I can drag a JPG file from the desktop to the Canvas and drop it and the DropObject Event fires but the if statement fails - obj.PictureAvailable is false

Allow Auto Deactivate is set to true
Enabled is set to true
Allow Focus Ring is set to true
Visible is set to true
Allow Focus is set to true.

The Canvas doesn’t display the picture but it fires the drop object event
(the focus ring never displays)

I have made this work in the past but I can’t seem to make it work now. What am I missing.

TIA

Of course, you tell your program that you will drop a Picture, not a graphics in a FolderItem…

Use Me.AcceptPictureDrop if you want to drag and drop a Picture inside your application (say between two windows of your application): from say Windo1.Canvas1 to Window2.Canvas2.
[sorry, that is what you want too]

You have to add If Obj.FolderItemAvailable Then and load the image from the file in that if block.…

Is it clear ?

Nope

I want to drag from a file on disk, not from another window.

I put the Obj.FolderItemAvailable statement in the DropObject event and now the If statement gives true and the imgDropPic = obj.picture line executes but the image still does not display and the Canvas.backdrop is nil after the operation.

See ‘Drag and Drop Pictures’ example:

my guess is that you are missing obj.FolderItemAvailable as Emile said. This is the DropObject event code from the example:

mDragInside = False
If obj.PictureAvailable Then
  mImage = obj.Picture
ElseIf obj.FolderItemAvailable Then
  mImage = Picture.Open(obj.FolderItem)
End If

Me.Refresh(False)

Ok, this seems to work. Now I just have to convert the image in the canvas to something I can put in a sqlite db

thank you

You’re mixing two things: files and pictures. A drag object can hold a picture alone or a folderitem (amont others, but that’s beyond this case).

If you drag&drop a picture file, the DragObject.FolderItemAvailable property will equal to true and DragObject.FolderItem will contain the file dropped. It’s then up to you to open the file as a picture, using Xojo’s methods.

If you drag&drop a picture (not a file, just a plain picture from another app/window), the DragObject.PictureAvailable property will be true and DragObject.Picture will contain the picture.

Those two are mutually exclusive: if a folderitem (file) is dropped, even if it represents a picture file, only the FolderItem/FolderItemAvailable properties will be useable. And, of course, if a plain picture is dropped (that isn’t a file), then the Picture/PictureAvailable properties will be used instead.

Is it clearer?