Skip to content

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 (clone)
Apple
Banana
Cherry
Date
Elderberry
Target
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

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.

Palette (an array)
Text box
Checkbox
Drop-down
Date
Form
Drag fields from the palette.

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, whose IsClone says the field is a copy.

How it works

  • The copy must be a distinct object: Blazor needs a unique @key per 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 Clone factory, an item that implements ICloneable is copied with Clone(), 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, Item is the copy and IsClone is true; OnRemove is 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

ParameterHereWhat it does
PullBortablePull.CloneItems leave this list as copies; the originals stay. The other values are Move (the default) and None.
CloneDuplicate, f => new Field(...)The factory that makes the copy.
Items_palette, an arrayA read-only list: shown, cloned from, never changed.
ItemLabelf => f.LabelHow announcements name an item; its ToString() without it.
OnAddOnFieldAddedRaised on the list an item was dropped into from another list.
An unhandled error has occurred. Reload 🗙