Cloning
Drag from the Source list to the Target. With Pull="BortablePull.Clone" a copy of the item goes into
the Target and the original stays in the Source - so the same item can be cloned again and again. The
Clone factory makes the copy.
A clone source
The Source still sorts within itself and takes items back from the Target - only what leaves it is a copy. The Target is an ordinary list: what is dragged out of it moves.
Source: Apple, Banana, Cherry, Date, Elderberry
Target: Item 1, Item 2, Item 3, Item 4, Item 5, Item 6
A read-only palette
A form builder: the palette is a plain array. A read-only list - an array, a ReadOnlyCollection<T>,
an ImmutableList<T> - is shown and can be cloned from, but it is never sorted, never pulled
from and never dropped into, so the palette needs no Sort or Put of its own and is
bound one way, with Items. Every field dropped into the form is a new object, so the same field can
be added twice.
Form:
Last added: nothing yet
Try it
- Drag Cherry into the Target twice: two Cherries arrive, and the Source keeps its own. With the mouse, the cursor shows a copy while the item is over the Target.
- Drag a Cherry from the Target back into the Source: it moves - the Target's own pull is the default,
Move. - Drag Banana down the Source: it sorts as usual.
-
Build a form from the palette, the same field more than once. The palette never changes, and
Last added comes from
OnAdd, whoseIsClonesays the field is a copy.
How it works
-
The copy must be a distinct object: Blazor needs a unique
@keyper item, so a copy that equals an item already in the target is refused. That is why the items here are classes, compared by reference - two records with the same values would be equal, and the second one refused. -
Without a
Clonefactory, an item that implementsICloneableis copied withClone(), and anything else is shared as it is - fine for an immutable reference type, refused for a value-equal duplicate such as the same string twice. -
In the events that follow the drop,
Itemis the copy andIsCloneistrue;OnRemoveis not raised, because nothing left the source. - Combined with swap mode, a clone source gives its item away in the swap rather than a copy; combined with multi-drag, dragging into another list clones only the dragged item.
Parameters on this page
| Parameter | Here | What it does |
|---|---|---|
Pull | BortablePull.Clone | Items leave this list as copies; the originals stay. The other values are Move (the default) and None. |
Clone | Duplicate, f => new Field(...) | The factory that makes the copy. |
Items | _palette, an array | A read-only list: shown, cloned from, never changed. |
ItemLabel | f => f.Label | How announcements name an item; its ToString() without it. |
OnAdd | OnFieldAdded | Raised on the list an item was dropped into from another list. |