Drag and Drop Library for Blazor
!This library is suitable if you need to make a small set of items draggable. It is not suitable to for large lists
https://blazordragdrop.azurewebsites.net/
Install-Package blazor-dragdrop
- Add BlazorDragDrop to your Startup.cs
services.AddBlazorDragDrop();
- Include relevant stylesheet either in your _host.cshtml (server-side blazor) or index.html (client-side blazor)
<link href="_content/blazor-dragdrop/dragdrop.css" rel="stylesheet" />
<Dropzone>
<Draggable>
<li class="list-group-item">Cras justo odio</li>
</Draggable>
<Draggable>
<li class="list-group-item">Morbi leo risus</li>
</Draggable>
<Dropzone>
<Dropzone>
</Dropzone>
Only allow limited number of items in a Dropzone:
<Dropzone MaxItems="2">
</Dropzone>
Restricted Dropzone: (executes the give accept func before accepting the draggable)
<Dropzone Accepts='(d) => d.Gender == "Male"'>
</Dropzone>
Attach data to draggables:
<Draggable Tag='new { Gender = "Female" , Age = 22}'>
<li class="list-group-item">Cras justo odio</li>
</Draggable>
Control if an element is draggable:
<Draggable AllowDrag="(d)=>MyFunc(d)">
<li class="list-group-item">Cras justo odio</li>
</Draggable>
Create a draggable list:
<Dropzone>
<ul class="list-group">
<Draggable>
<li class="list-group-item">Cras justo odio</li>
</Draggable>
<Draggable>
<li class="list-group-item">Dapibus ac facilisis in</li>
</Draggable>
<Draggable>
<li class="list-group-item">Morbi leo risus</li>
</Draggable>
<Draggable>
<li class="list-group-item">Porta ac consectetur ac</li>
</Draggable>
<Draggable>
<li class="list-group-item">Vestibulum at eros</li>
</Draggable>
</ul>
</Dropzone>
The HTML 5 drag'n'drop API allows to implement drag'n'drop on most desktop browsers.
Unfortunately, most mobile browsers don't support it.
You need to make use of a polyfill library, e.g. mobile-drag-drop
Add this to your _host.html:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mobile-drag-drop@2.3.0-rc.2/default.css">
<script src="https://cdn.jsdelivr.net/npm/mobile-drag-drop@2.3.0-rc.2/index.min.js"></script>
<script>
// options are optional ;)
MobileDragDrop.polyfill({
// use this to make use of the scroll behaviour
dragImageTranslateOverride: MobileDragDrop.scrollBehaviourDragImageTranslateOverride
});
</script>