Postlagerkarte / blazor-dragdrop

Easy-to-use Drag and Drop Library for Blazor
MIT License
403 stars 96 forks source link

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

Open qplace1 opened 2 years ago

qplace1 commented 2 years ago

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!

vkristijan commented 2 years ago

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 commented 2 years ago

@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.