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

Startup.cs vs Program.cs and ActiveItem equals null #142

Open
qplace1 opened this issue Apr 17, 2022 · 2 comments
Open

Startup.cs vs Program.cs and ActiveItem equals null #142

qplace1 opened this issue Apr 17, 2022 · 2 comments

Comments

@qplace1
Copy link

qplace1 commented Apr 17, 2022

Documentation states:
Add BlazorDragDrop to your Startup.cs
services.AddBlazorDragDrop();

.net 6 requires usage of Program.cs.

So, I am using builder.Services.AddBlazorDragDrop(); in Program.cs

The problem I am having is that in my project, derived from the Demo project, the methods copiedItem or acceptItem are never called:

<div style="border:solid; width:700px; margin-top:50px" >
    <Dropzone Items="Controls" TItem="ControlData"  
            CopyItem="copiedItem"
            Accepts='acceptItem'
    >
        <DesignerControl Item=@context></DesignerControl>
    </Dropzone>
</div>

private ControlData copiedItem(ControlData item)
{
      return new ControlData(item.controlType);
}

private bool acceptItem(ControlData t1, ControlData t2)
{
     return true;
}

I added the DragDrop project to my solution to try to figure out what is going on. In dropzone.cs, line 311, in the method:
private bool IsDropAllowed()
{
var activeItem = DragDropService.ActiveItem;
...
the variable activeItem is always null.

What am I doing wrong? Any advise, or help for which I'll gladly pay will be greatly appreciated.
Thanks!

@qplace1 qplace1 changed the title Startup.cs vs Program.cs in Startup.cs vs Program.cs Apr 17, 2022
@qplace1 qplace1 changed the title Startup.cs vs Program.cs Startup.cs vs Program.cs and ActiveItem equall null Apr 17, 2022
@qplace1 qplace1 changed the title Startup.cs vs Program.cs and ActiveItem equall null Startup.cs vs Program.cs and ActiveItem equals null Apr 18, 2022
@vkristijan
Copy link
Collaborator

It should be ok to use builder.Services.AddBlazorDragDrop(); in Program.cs

As for your other 2 questions, CopyItem works only across different DropZones, if you are dragging an item within the same DropZone, it will not be called.
I wasn't able to replicate the Accepts method not being called. The method you provided in the example returns always true. Can you try placing a breakpoint in it to see if it gets hit?

Lastly, the activeItem shouldn't be null at that point as it was set in the OnDragStart method :)

@qplace1
Copy link
Author

qplace1 commented Apr 25, 2022

@vkristijan : Thank you!
I think that the issue with Accept is a derivative of me skipping DropZone from the source item. Making change, will report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants