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

Add support to IDragHandler to specify a produced object for the drag drop payload #111

Open
stevemonaco opened this issue Nov 18, 2022 · 0 comments

Comments

@stevemonaco
Copy link

stevemonaco commented Nov 18, 2022

Currently, ContentDragBehavior will forward only the binded Context into the drag+drop interaction. IDragHandler.BeforeDragDrop does not seem to allow for a produced value to be specified as the drag+drop payload.

Use case: I have an image editor where I make selections and drag+drop to replace contents. There is no backing collection and as such it doesn't work like a collection control. The source Context is the VM because there is logic that I want to run before drag initiated.

I want to produce the payload (an object with copied image data and/or tile metadata) at drag initiation because it's expensive to repeatedly create during selection. I also want the drag+drop interaction to "own" the payload at that point so that the source VM doesn't need to. I have already done this locally by extending IDragHandler and creating a modified ContextDragBehavior, though this is probably not an appropriate API for the library if you can break IDragHandler.BeforeDragDrop.

My local changes:

public interface IDragHandlerEx : IDragHandler
{
    public object? Payload { get; set; }
}

I have modified ContextDragBehavior to use IDragHandlerEx and this area of ContextDragBehavior to:

var context = Context ?? AssociatedObject?.DataContext;
Handler?.BeforeDragDrop(sender, _triggerEvent, context);

var payload = Handler?.Payload ?? context;
await DoDragDrop(_triggerEvent, payload);

Handler?.AfterDragDrop(sender, _triggerEvent, context); // This may need payload as an extra parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants