AstrolUI AstrolUI
Amarillo Naranja Rojo Verde Azul Morado Color propio
Modo claro
Ejemplos

Cada ejemplo es un componente completo: copie su código (marcado y @code) con los datos de prueba y sustitúyalos por los suyos.

1. Tablero básico

Cajas con contenido propio (BoxRender) y relaciones. OnChangeBoard informa de cada cambio.
100%
Design
Ana
Build
Luis
Test
Eva

Move a box.

@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* Drag the boxes, resize them from the corners, Ctrl+click to select several, arrows to move them,
   Ctrl+Z / Ctrl+Y, Ctrl+F to search and Ctrl+wheel to zoom. *@
<div style="height:380px">
    <AstrolBoard TBox="WorkItem" TRelation="object"
                 Board="board"
                 BackgroundType="BackgroundType.Points"
                 MinWidth="80"
                 MinHeight="60"
                 OnChangeBoard="OnChange">
        <BoxRender>
            <div style="height:100%; padding:8px; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg); overflow:hidden">
                <b>@context.BOX_NAME</b>
                <div style="font-size:.8em; opacity:.8">@context.Content.Owner</div>
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
<p aria-live="polite">@message</p>
 
@code {
    private string message = "Move a box.";
    private readonly Board<WorkItem, object> board = Create();
 
    private void OnChange(Board<WorkItem, object> changed)
    {
        var first = changed.Boxes[0];
        message = $"{first.BOX_NAME}: X {first.X:0}, Y {first.Y:0}, {first.Width:0} x {first.Height:0}";
    }
 
    private static Board<WorkItem, object> Create()
    {
        var b = new Board<WorkItem, object>();
        b.Boxes.Add(new Box<WorkItem> { X = 30, Y = 40, Width = 160, Height = 90, BOX_NAME = "Design", Content = new WorkItem { Owner = "Ana" } });
        b.Boxes.Add(new Box<WorkItem> { X = 290, Y = 40, Width = 160, Height = 90, BOX_NAME = "Build", Content = new WorkItem { Owner = "Luis" } });
        b.Boxes.Add(new Box<WorkItem> { X = 290, Y = 220, Width = 160, Height = 90, BOX_NAME = "Test", Content = new WorkItem { Owner = "Eva" } });
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[0].Id, BoxIdB = b.Boxes[1].Id });
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[1].Id, BoxIdB = b.Boxes[2].Id });
        return b;
    }
 
    public class WorkItem
    {
        public string Owner { get; set; } = string.Empty;
    }
}

2. Editor de diagramas

Todas las herramientas juntas: flechas y etiquetas en las relaciones; pase el ratón por una caja y arrastre uno de sus cuatro círculos hasta otra caja para conectarlas; arrastre el fondo para seleccionar con un rectángulo (Mayús + arrastrar desplaza); las cajas se ajustan a la cuadrícula y se alinean con las demás; Ctrl+C, Ctrl+V, Ctrl+D y Supr copian, pegan, duplican y borran (con sus relaciones). Clic derecho en una línea para cambiar sus flechas o su etiqueta.
Hover a box and drag one of its circles to another box.
100%
Yes
No
Start
Is it valid?
Save
Fix the data
End
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* A small diagram editor with the built-in tools:
   - Arrows (RelationArrow / Relation.Arrow) and labels (Relation.Label or RelationRender).
   - AllowConnect: hover a box and drag one of its four circles to another box; OnConnect completes the relation.
   - BackgroundDrag: drag the background to select with a rectangle (Shift + drag scrolls) or the other way round.
   - SnapToGrid / SnapToBoxes: boxes snap to a 20 px grid and align with the edges and centers of the others.
   - Ctrl+C / Ctrl+V / Ctrl+D copy, paste and duplicate (with the relations between them); Delete removes the
     selection and its relations (when OnKeyDownDelete is not used). Ctrl+Z undoes everything. *@
<div class="diagram-options">
    <button type="button" class="@(dragSelect ? "on" : null)" @onclick="() => dragSelect = !dragSelect">Drag selects</button>
    <button type="button" class="@(snap ? "on" : null)" @onclick="() => snap = !snap">Snap</button>
    <button type="button" class="@(curved ? "on" : null)" @onclick="() => curved = !curved">Curved</button>
    <span class="diagram-hint">@hint</span>
</div>
<div style="height:440px">
    <AstrolBoard TBox="string" TRelation="object"
                 @ref="boardRef"
                 Board="board"
                 RelationAnchor="RelationAnchor.Border"
                 RelationArrow="RelationArrow.End"
                 LineStyle="@(curved ? RelationLineStyle.Curved : RelationLineStyle.Straight)"
                 AllowConnect="true"
                 EditAnchors="true"
                 BackgroundDrag="@(dragSelect ? BoardBackgroundDrag.Select : BoardBackgroundDrag.Pan)"
                 SnapToGrid="@(snap ? 20 : 0)"
                 SnapToBoxes="snap"
                 MinWidth="60" MinHeight="40"
                 ShowBoardContextMenu="true"
                 ShowBoxContextMenu="true"
                 ShowRelationContextMenu="true"
                 OnOpenBoardContextMenu="p => { position = p; }"
                 OnOpenRelationContextMenu="e => { (relationA, relationB, _) = e; }"
                 OnConnect="Connect"
                 OnBoxesAdded="Added"
                 OnBoxesRemoved="Removed">
        <BoardContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-plus" Text="New box here" OnClick="AddBox" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-paste" Text="Paste" KeyboardShortcut="Ctrl+V" OnClick="() => boardRef!.PasteAsync()" />
        </BoardContextMenu>
        <BoxContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-docs" Text="Copy" KeyboardShortcut="Ctrl+C" OnClick="() => boardRef!.CopySelection()" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-clone" Text="Duplicate" KeyboardShortcut="Ctrl+D" OnClick="() => boardRef!.DuplicateSelectionAsync()" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-trash" IconColor="var(--aui-danger)" Text="Delete" KeyboardShortcut="Supr" OnClick="() => boardRef!.DeleteSelectionAsync()" />
        </BoxContextMenu>
        <RelationContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-forward" Text="Arrow A → B" OnClick="() => SetArrow(RelationArrow.End)" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-resize-horizontal" Text="Arrows A ↔ B" OnClick="() => SetArrow(RelationArrow.Both)" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-minus" Text="No arrows" OnClick="() => SetArrow(RelationArrow.None)" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-ok" Text="Label «Yes»" OnClick="@(() => SetLabel("Yes"))" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-cancel" Text="Label «No»" OnClick="@(() => SetLabel("No"))" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-minus" Text="Remove label" OnClick="@(() => SetLabel(null))" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-unlink" IconColor="var(--aui-danger)" Text="Delete relation" OnClick="DeleteRelation" />
        </RelationContextMenu>
        <BoxRender>
            <div class="diagram-box @(context.Content)">@context.BOX_NAME</div>
        </BoxRender>
    </AstrolBoard>
</div>
 
<style>
    .diagram-options {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 5px;
        margin-bottom: 5px;
    }
 
        .diagram-options button {
            padding: 4px 12px;
            border-radius: 5px;
            border: 1px solid var(--color-gray-a);
            background: var(--layout-menu-bg);
            color: inherit;
            cursor: pointer;
        }
 
            .diagram-options button.on {
                background: var(--color-base);
                border-color: var(--color-base);
                color: var(--color-dark);
            }
 
    .diagram-hint {
        margin-left: 8px;
        opacity: .8;
        font-size: .9em;
    }
 
    .diagram-box {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        border-radius: 8px;
        border: 1px solid var(--color-gray-a);
        background: var(--layout-menu-bg);
        font-size: .9em;
    }
 
        .diagram-box.start {
            border-radius: 999px;
            background: var(--color-base);
            color: var(--color-dark);
            border-color: var(--color-base);
        }
 
        .diagram-box.decision {
            border-style: dashed;
            border-color: var(--color-orange);
        }
</style>
 
@code {
    private AstrolBoard<string, object>? boardRef;
    private readonly Board<string, object> board = Create();
    private Position position = new();
    private string? relationA, relationB;
    private bool dragSelect = true;
    private bool snap = true;
    private bool curved;
    private string hint = "Hover a box and drag one of its circles to another box.";
 
    private Relation<object> Relation => board.Relations.First(r => r.BoxIdA == relationA && r.BoxIdB == relationB);
 
    // The relation is not on the board yet: complete it or cancel it.
    private void Connect(BoardConnectEventArgs<object> e)
    {
        if (board.Relations.Any(r => r.BoxIdA == e.Relation.BoxIdA && r.BoxIdB == e.Relation.BoxIdB))
        {
            e.Cancel = true;
            hint = "Those boxes are already connected.";
            return;
        }
        hint = "Relation added. Right-click on it to change its arrows or its label.";
    }
 
    private void Added(IReadOnlyList<Box<string>> boxes) => hint = $"{boxes.Count} box(es) added.";
 
    private void Removed(BoardRemovedEventArgs<string, object> e) =>
        hint = $"{e.Boxes.Count} box(es) and {e.Relations.Count} relation(s) removed.";
 
    private void AddBox()
    {
        board.Boxes.Add(new Box<string>
        {
            X = position.X / board.Scale,
            Y = position.Y / board.Scale,
            Width = 120,
            Height = 50,
            BOX_NAME = $"Step {board.Boxes.Count + 1}",
            Content = "",
        });
    }
 
    private void SetArrow(RelationArrow arrow) => Relation.Arrow = arrow;
 
    private void SetLabel(string? label) => Relation.Label = label!;
 
    private void DeleteRelation() => board.Relations.Remove(Relation);
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        void Box(string id, string name, float x, float y, string kind = "") =>
            b.Boxes.Add(new Box<string> { Id = id, X = x, Y = y, Width = 120, Height = 50, BOX_NAME = name, Content = kind });
 
        Box("start", "Start", 40, 40, "start");
        Box("check", "Is it valid?", 40, 160, "decision");
        Box("save", "Save", 280, 160);
        Box("fix", "Fix the data", 40, 300);
        Box("end", "End", 520, 160, "start");
 
        b.Relations.Add(new Relation<object> { BoxIdA = "start", BoxIdB = "check" });
        b.Relations.Add(new Relation<object> { BoxIdA = "check", BoxIdB = "save", Label = "Yes" });
        b.Relations.Add(new Relation<object> { BoxIdA = "check", BoxIdB = "fix", Label = "No" });
        b.Relations.Add(new Relation<object> { BoxIdA = "save", BoxIdB = "end" });
        b.Relations.Add(new Relation<object>
        {
            BoxIdA = "fix",
            BoxIdB = "check",
            AnchorA = BoxAnchor.Right,
            AnchorB = new BoxAnchor(1, 0.75F),
            Vertices = new List<Vertex> { new() { X = 200, Y = 325, Order = 1 }, new() { X = 200, Y = 197, Order = 2 } },
        });
        return b;
    }
}

3. Menú contextual del tablero y de las cajas

Clic derecho en el fondo del tablero (insertar una caja, pegar, ordenar) o en una caja (color, copiar, duplicar, conectar, traer al frente, borrar); también en una línea o un vértice. Las opciones usan MenuOpion (icono, texto, atajo, separador y opción desactivada).

Right-click on the board or on a box.

100%
Box 1
Box 2
Box 3
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* Right-click on the empty board or on a box (also on a line or on a vertex). Each menu is a RenderFragment;
   MenuOpion is a ready-made option (icon, text, shortcut, separator, disabled). The events give the id and the
   click position in board pixels (divide by Scale to get model units). *@
<p style="margin:0 0 5px">@status</p>
<div style="height:400px">
    <AstrolBoard TBox="string" TRelation="object"
                 Board="board"
                 RelationAnchor="RelationAnchor.Border"
                 ShowBoardContextMenu="true"
                 ShowBoxContextMenu="true"
                 ShowRelationContextMenu="true"
                 ShowVertexContextMenu="true"
                 OnOpenBoardContextMenu="p => { position = p; }"
                 OnOpenBoxContextMenu="e => { (boxId, position) = e; }"
                 OnOpenRelationContextMenu="e => { (relationA, relationB, position) = e; }"
                 OnOpenVertexContextMenu="e => { (vertexId, position) = e; }">
        <BoardContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-plus" Text="New box here" OnClick="AddBox" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-paste" Text="Paste box" Status="copied != null" OnClick="Paste" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-sitemap" Text="Arrange in a row" OnClick="Arrange" />
        </BoardContextMenu>
        <BoxContextMenu>
            <div class="menu-colors">
                @foreach (var color in Colors)
                {
                    <button type="button" title="@color" style="background:@color" @onclick="() => SetColor(color)"></button>
                }
            </div>
            <MenuOpion NeedAuthorize="false" Icon="astrol-docs" Text="Copy" OnClick="Copy" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-clone" Text="Duplicate" OnClick="Duplicate" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-link" Text="Connect to the next box" OnClick="ConnectToNext" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-level-up" Text="Bring to front" OnClick="BringToFront" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-trash" IconColor="var(--aui-danger)" Text="Delete" OnClick="DeleteBox" />
        </BoxContextMenu>
        <RelationContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-plus" Text="Add vertex here" OnClick="AddVertex" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-unlink" IconColor="var(--aui-danger)" Text="Delete relation" OnClick="DeleteRelation" />
        </RelationContextMenu>
        <VertexContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-trash" IconColor="var(--aui-danger)" Text="Delete vertex" OnClick="DeleteVertex" />
        </VertexContextMenu>
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; color:#fff; font-weight:600; background:@context.Color">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
<style>
    .menu-colors {
        display: flex;
        gap: 6px;
        padding: 4px 5px 8px;
    }
 
        .menu-colors button {
            width: 22px;
            height: 22px;
            border: 2px solid var(--color-white);
            border-radius: 50%;
            box-shadow: var(--shadow-control);
            cursor: pointer;
        }
</style>
 
@code {
    private static readonly string[] Colors = { "var(--color-base)", "var(--color-blue)", "var(--color-green)", "var(--color-orange)", "var(--color-red)" };
 
    private readonly Board<string, object> board = Create();
    private Position position = new();
    private string? boxId, relationA, relationB, vertexId;
    private Box<string>? copied;
    private string status = "Right-click on the board or on a box.";
 
    private Box<string> Selected => board.Boxes.First(b => b.Id == boxId);
 
    private void AddBox()
    {
        board.Boxes.Add(NewBox(position.X / board.Scale, position.Y / board.Scale, $"Box {board.Boxes.Count + 1}"));
        status = "Box added.";
    }
 
    private void Copy()
    {
        copied = Selected;
        status = $"\"{copied.BOX_NAME}\" copied: right-click on the board to paste it.";
    }
 
    private void Paste()
    {
        var box = NewBox(position.X / board.Scale, position.Y / board.Scale, copied!.BOX_NAME + " (copy)");
        box.Color = copied.Color;
        box.Width = copied.Width;
        box.Height = copied.Height;
        board.Boxes.Add(box);
        status = "Box pasted.";
    }
 
    private void Duplicate()
    {
        var source = Selected;
        var box = NewBox(source.X + 20, source.Y + 20, source.BOX_NAME + " (copy)");
        box.Color = source.Color;
        board.Boxes.Add(box);
        status = "Box duplicated.";
    }
 
    private void SetColor(string color)
    {
        Selected.Color = color;
        status = $"Color of \"{Selected.BOX_NAME}\" changed.";
    }
 
    // The last box of the list is painted on top.
    private void BringToFront()
    {
        var box = Selected;
        board.Boxes.Remove(box);
        board.Boxes.Add(box);
        status = $"\"{box.BOX_NAME}\" brought to front.";
    }
 
    private void Arrange()
    {
        float x = 30;
        foreach (var box in board.Boxes)
        {
            box.X = x;
            box.Y = 40;
            x += box.Width + 30;
        }
        status = "Boxes arranged.";
    }
 
    private void DeleteBox()
    {
        board.Boxes.RemoveAll(b => b.Id == boxId);
        board.Relations.RemoveAll(r => r.BoxIdA == boxId || r.BoxIdB == boxId);
        status = "Box deleted (Ctrl+Z restores it).";
    }
 
    private void ConnectToNext()
    {
        var index = board.Boxes.FindIndex(b => b.Id == boxId);
        var next = board.Boxes[(index + 1) % board.Boxes.Count];
        if (next.Id != boxId && !board.Relations.Any(r => r.BoxIdA == boxId && r.BoxIdB == next.Id))
        {
            board.Relations.Add(new Relation<object> { BoxIdA = boxId!, BoxIdB = next.Id });
            status = "Relation added.";
        }
    }
 
    private void AddVertex()
    {
        var relation = board.Relations.First(r => r.BoxIdA == relationA && r.BoxIdB == relationB);
        relation.Vertices.Add(new Vertex
        {
            X = position.X / board.Scale,
            Y = position.Y / board.Scale,
            Order = relation.Vertices.Count + 1,
        });
        status = "Vertex added: drag it to bend the line.";
    }
 
    private void DeleteRelation()
    {
        board.Relations.RemoveAll(r => r.BoxIdA == relationA && r.BoxIdB == relationB);
        status = "Relation deleted.";
    }
 
    private void DeleteVertex()
    {
        foreach (var relation in board.Relations)
        {
            relation.Vertices.RemoveAll(v => v.Id == vertexId);
        }
        status = "Vertex deleted.";
    }
 
    private static Box<string> NewBox(float x, float y, string name) =>
        new() { X = x, Y = y, Width = 120, Height = 70, BOX_NAME = name, Content = "" };
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        b.Boxes.Add(NewBox(40, 60, "Box 1"));
        b.Boxes.Add(NewBox(320, 60, "Box 2"));
        b.Boxes.Add(NewBox(180, 240, "Box 3"));
        b.Boxes[1].Color = "var(--color-blue)";
        b.Boxes[2].Color = "var(--color-green)";
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[0].Id, BoxIdB = b.Boxes[1].Id });
        return b;
    }
}

4. Anclaje y forma de las líneas

RelationAnchor elige si las líneas salen del centro o del borde de las cajas y LineStyle si son rectas o curvas. Con EditAnchors, pase el ratón por una línea o por una caja y arrastre el círculo del extremo (se dibuja encima de la caja) a cualquier punto del borde; doble clic lo libera. «Done» tiene una relación consigo misma (bucle).
100%
Start
Review
Rework
Done
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* RelationAnchor: lines start at the center of the boxes (Center) or at their border (Border).
   LineStyle: straight lines (Straight) or smooth curves (Curved) that leave each box perpendicular to its side.
   Relation.AnchorA / AnchorB fix a point of each box (0..1, relative to the box).
   EditAnchors: hover a line or a box (selected or not) and drag the circle at the end of the line (drawn over the box) to any
   point of the border; it snaps to corners, quarters and middles. Double-click the circle to release it.
   The right-click menu of a line also sets them. "Done" has a relation with itself: a loop. *@
<div class="anchor-options">
    <button type="button" class="@(mode == RelationAnchor.Center ? "on" : null)" @onclick="() => mode = RelationAnchor.Center">Center</button>
    <button type="button" class="@(mode == RelationAnchor.Border ? "on" : null)" @onclick="() => mode = RelationAnchor.Border">Border</button>
    <span class="anchor-separator"></span>
    <button type="button" class="@(lineStyle == RelationLineStyle.Straight ? "on" : null)" @onclick="() => lineStyle = RelationLineStyle.Straight">Straight</button>
    <button type="button" class="@(lineStyle == RelationLineStyle.Curved ? "on" : null)" @onclick="() => lineStyle = RelationLineStyle.Curved">Curved</button>
    <span class="anchor-separator"></span>
    <button type="button" class="@(editAnchors ? "on" : null)" aria-pressed="@(editAnchors ? "true" : "false")" @onclick="() => editAnchors = !editAnchors">EditAnchors</button>
</div>
<div style="height:400px">
    <AstrolBoard TBox="string" TRelation="object"
                 Board="board"
                 RelationAnchor="mode"
                 LineStyle="lineStyle"
                 EditAnchors="editAnchors"
                 BackgroundType="BackgroundType.Points"
                 ShowRelationContextMenu="true"
                 OnOpenRelationContextMenu="e => { (relationA, relationB, _) = e; }">
        <RelationContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-forward" Text="From the right to the left side" OnClick="() => Fix(BoxAnchor.Right, BoxAnchor.Left)" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-down" Text="From the bottom to the top side" OnClick="() => Fix(BoxAnchor.Bottom, BoxAnchor.Top)" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-target" Text="Release (use the general mode)" OnClick="() => Fix(null, null)" />
        </RelationContextMenu>
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg)">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
<style>
    .anchor-options {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        margin-bottom: 5px;
    }
 
        .anchor-options button {
            padding: 4px 12px;
            border-radius: 5px;
            border: 1px solid var(--color-gray-a);
            background: var(--layout-menu-bg);
            color: inherit;
            cursor: pointer;
        }
 
            .anchor-options button.on {
                background: var(--color-base);
                border-color: var(--color-base);
                color: var(--color-dark);
            }
    .anchor-separator {
        width: 1px;
        margin: 2px 4px;
        background: var(--color-gray-a);
    }
</style>
 
@code {
    private RelationAnchor mode = RelationAnchor.Border;
    private RelationLineStyle lineStyle = RelationLineStyle.Curved;
    private bool editAnchors = true;
    private string? relationA, relationB;
    private readonly Board<string, object> board = Create();
 
    private void Fix(BoxAnchor? a, BoxAnchor? b)
    {
        var relation = board.Relations.First(r => r.BoxIdA == relationA && r.BoxIdB == relationB);
        relation.AnchorA = a;
        relation.AnchorB = b;
    }
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        b.Boxes.Add(new Box<string> { X = 40, Y = 140, Width = 130, Height = 70, BOX_NAME = "Start", Content = "" });
        b.Boxes.Add(new Box<string> { X = 280, Y = 40, Width = 130, Height = 70, BOX_NAME = "Review", Content = "" });
        b.Boxes.Add(new Box<string> { X = 280, Y = 250, Width = 130, Height = 70, BOX_NAME = "Rework", Content = "" });
        b.Boxes.Add(new Box<string> { X = 520, Y = 140, Width = 130, Height = 70, BOX_NAME = "Done", Content = "" });
 
        // No anchors: they follow RelationAnchor (center or border)
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[0].Id, BoxIdB = b.Boxes[1].Id });
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[0].Id, BoxIdB = b.Boxes[2].Id });
 
        // Fixed anchors: from the right side of "Review" / "Rework" to the left side of "Done"
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[1].Id, BoxIdB = b.Boxes[3].Id, AnchorA = BoxAnchor.Right, AnchorB = new BoxAnchor(0, 0.25F) });
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[2].Id, BoxIdB = b.Boxes[3].Id, AnchorA = BoxAnchor.Right, AnchorB = new BoxAnchor(0, 0.75F) });
 
        // Fixed anchors: from the bottom of "Review" to the top of "Rework"
        b.Relations.Add(new Relation<object>
        {
            BoxIdA = b.Boxes[1].Id,
            BoxIdB = b.Boxes[2].Id,
            AnchorA = new BoxAnchor(0.75F, 1),
            AnchorB = new BoxAnchor(0.75F, 0),
        });
 
        // A relation of a box with itself: a loop at its bottom-right corner
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[3].Id, BoxIdB = b.Boxes[3].Id });
        return b;
    }
}

5. Vértices con menú contextual

Clic derecho en una línea: añadir un vértice justo donde se hizo clic (en el tramo correcto), trazar un ángulo recto o enderezarla. Clic derecho en un vértice: alinearlo con el punto anterior, ajustarlo a la cuadrícula, duplicarlo o borrarlo. Arrastre un vértice para moverlo.

Right-click on a line or on a vertex.

100%
Source
Target
Input
Output
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* Vertices bend a relation: the line goes through them in Order. Right-click on a line to add a vertex
   exactly where you clicked (between the right points), straighten it or route it with a right angle;
   right-click on a vertex to delete, duplicate, align or snap it to the grid. Drag a vertex to move it. *@
<p style="margin:0 0 5px">@status</p>
<div style="height:420px">
    <AstrolBoard TBox="string" TRelation="object"
                 Board="board"
                 RelationAnchor="RelationAnchor.Border"
                 ShowRelationContextMenu="true"
                 ShowVertexContextMenu="true"
                 OnOpenRelationContextMenu="e => { (relationA, relationB, position) = e; }"
                 OnOpenVertexContextMenu="e => { (vertexId, position) = e; }">
        <RelationContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-plus" Text="Add vertex here" OnClick="AddVertex" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-flow-split" Text="Right-angle route" OnClick="RightAngle" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-resize-horizontal" Text="Straighten (remove vertices)" Status="board.Relations.Any(r => r.BoxIdA == relationA && r.BoxIdB == relationB && r.Vertices.Count > 0)" OnClick="Straighten" />
        </RelationContextMenu>
        <VertexContextMenu>
            <MenuOpion NeedAuthorize="false" Icon="astrol-resize-horizontal" Text="Align horizontally with the previous point" OnClick="() => Align(horizontal: true)" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-resize-vertical" Text="Align vertically with the previous point" OnClick="() => Align(horizontal: false)" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-target" Text="Snap to the grid (20 px)" OnClick="Snap" HasSeparator="true" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-clone" Text="Duplicate vertex" OnClick="Duplicate" />
            <MenuOpion NeedAuthorize="false" Icon="astrol-trash" IconColor="var(--aui-danger)" Text="Delete vertex" OnClick="Delete" />
        </VertexContextMenu>
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg)">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
@code {
    private readonly Board<string, object> board = Create();
    private Position position = new();
    private string? relationA, relationB, vertexId;
    private string status = "Right-click on a line or on a vertex.";
 
    private Relation<object> Relation => board.Relations.First(r => r.BoxIdA == relationA && r.BoxIdB == relationB);
 
    private Relation<object> RelationOfVertex => board.Relations.First(r => r.Vertices.Any(v => v.Id == vertexId));
 
    private Vertex SelectedVertex => RelationOfVertex.Vertices.First(v => v.Id == vertexId);
 
    private static (float X, float Y) Center(Box<string> box) => (box.X + box.Width / 2, box.Y + box.Height / 2);
 
    // Points of the line in order: box A, the vertices, box B.
    private List<(float X, float Y)> Points(Relation<object> relation)
    {
        var points = new List<(float X, float Y)> { Center(board.Boxes.First(b => b.Id == relation.BoxIdA)) };
        points.AddRange(relation.Vertices.OrderBy(v => v.Order).Select(v => (v.X, v.Y)));
        points.Add(Center(board.Boxes.First(b => b.Id == relation.BoxIdB)));
        return points;
    }
 
    private static void Renumber(Relation<object> relation, List<Vertex> ordered)
    {
        for (var i = 0; i < ordered.Count; i++)
        {
            ordered[i].Order = i + 1;
        }
        relation.Vertices = ordered;
    }
 
    private void AddVertex()
    {
        // The click position is in board pixels: divide by Scale to get model units.
        var x = position.X / board.Scale;
        var y = position.Y / board.Scale;
        var relation = Relation;
        var points = Points(relation);
 
        // Insert it in the segment closest to the click, so the line does not cross itself.
        var segment = Enumerable.Range(0, points.Count - 1).MinBy(i => Distance(points[i], points[i + 1], x, y));
        var ordered = relation.Vertices.OrderBy(v => v.Order).ToList();
        ordered.Insert(segment, new Vertex { X = x, Y = y });
        Renumber(relation, ordered);
        status = $"Vertex added ({ordered.Count} in this line). Drag it to bend the line.";
    }
 
    private void Straighten()
    {
        Relation.Vertices = new List<Vertex>();
        status = "Line straightened.";
    }
 
    private void RightAngle()
    {
        var relation = Relation;
        var a = Center(board.Boxes.First(b => b.Id == relation.BoxIdA));
        var b = Center(board.Boxes.First(b => b.Id == relation.BoxIdB));
        relation.Vertices = new List<Vertex> { new() { X = b.X, Y = a.Y, Order = 1 } };
        status = "Right-angle route: one vertex at the corner.";
    }
 
    private void Align(bool horizontal)
    {
        var relation = RelationOfVertex;
        var vertex = SelectedVertex;
        var points = Points(relation);
        var index = relation.Vertices.OrderBy(v => v.Order).ToList().IndexOf(vertex) + 1; // +1: points[0] is box A
        var previous = points[index - 1];
        if (horizontal)
        {
            vertex.Y = previous.Y;
        }
        else
        {
            vertex.X = previous.X;
        }
        status = horizontal ? "Vertex aligned horizontally." : "Vertex aligned vertically.";
    }
 
    private void Snap()
    {
        var vertex = SelectedVertex;
        vertex.X = MathF.Round(vertex.X / 20) * 20;
        vertex.Y = MathF.Round(vertex.Y / 20) * 20;
        status = $"Vertex snapped to ({vertex.X}, {vertex.Y}).";
    }
 
    private void Duplicate()
    {
        var relation = RelationOfVertex;
        var vertex = SelectedVertex;
        var ordered = relation.Vertices.OrderBy(v => v.Order).ToList();
        ordered.Insert(ordered.IndexOf(vertex) + 1, new Vertex { X = vertex.X + 30, Y = vertex.Y + 30 });
        Renumber(relation, ordered);
        status = "Vertex duplicated.";
    }
 
    private void Delete()
    {
        var relation = RelationOfVertex;
        Renumber(relation, relation.Vertices.Where(v => v.Id != vertexId).OrderBy(v => v.Order).ToList());
        status = "Vertex deleted (Ctrl+Z restores it).";
    }
 
    // Distance from (x, y) to the segment p-q.
    private static float Distance((float X, float Y) p, (float X, float Y) q, float x, float y)
    {
        var dx = q.X - p.X;
        var dy = q.Y - p.Y;
        var length = dx * dx + dy * dy;
        var t = length == 0 ? 0 : Math.Clamp(((x - p.X) * dx + (y - p.Y) * dy) / length, 0, 1);
        var cx = p.X + t * dx - x;
        var cy = p.Y + t * dy - y;
        return MathF.Sqrt(cx * cx + cy * cy);
    }
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        b.Boxes.Add(new Box<string> { X = 40, Y = 40, Width = 120, Height = 70, BOX_NAME = "Source", Content = "" });
        b.Boxes.Add(new Box<string> { X = 480, Y = 110, Width = 120, Height = 70, BOX_NAME = "Target", Content = "" });
        b.Boxes.Add(new Box<string> { X = 40, Y = 280, Width = 120, Height = 70, BOX_NAME = "Input", Content = "" });
        b.Boxes.Add(new Box<string> { X = 480, Y = 280, Width = 120, Height = 70, BOX_NAME = "Output", Content = "" });
 
        // A straight line, a line with two vertices and a right-angle route
        b.Relations.Add(new Relation<object> { BoxIdA = b.Boxes[0].Id, BoxIdB = b.Boxes[1].Id });
        b.Relations.Add(new Relation<object>
        {
            BoxIdA = b.Boxes[2].Id,
            BoxIdB = b.Boxes[3].Id,
            Vertices = new List<Vertex>
            {
                new() { X = 240, Y = 220, Order = 1 },
                new() { X = 400, Y = 380, Order = 2 },
            },
        });
        b.Relations.Add(new Relation<object>
        {
            BoxIdA = b.Boxes[0].Id,
            BoxIdB = b.Boxes[3].Id,
            Vertices = new List<Vertex> { new() { X = 100, Y = 235, Order = 1 }, new() { X = 540, Y = 235, Order = 2 } },
        });
        return b;
    }
}

6. Ordenar automáticamente

ArrangeAsync ordena todas las cajas según sus relaciones, por capas y con los mínimos cruces; las relaciones largas reciben vértices para rodear las cajas. Pulse Shuffle para desordenarlo y vuelva a ordenarlo de arriba abajo o de izquierda a derecha; Ctrl+Z lo deshace.
100%
Request
Validate
Approve
Reject
Notify
Pay
Ship
Invoice
Close
Audit
Archive
Help desk
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* ArrangeAsync orders every box by its relations: by layers, with as few crossings as possible and each box
   aligned with its neighbors. Long relations get vertices so they go around the boxes. It only moves boxes and
   vertices (relations are never added, removed or changed), it goes into the history (Ctrl+Z) and raises
   OnChangeBoard. BoardLayout.Arrange(board, options) does the same without the component (e.g. on the server). *@
<div class="arrange-options">
    <button type="button" @onclick="() => Arrange(BoardLayoutDirection.TopToBottom)"><i class="astrol-down"></i> Arrange top to bottom</button>
    <button type="button" @onclick="() => Arrange(BoardLayoutDirection.LeftToRight)"><i class="astrol-forward"></i> Arrange left to right</button>
    <button type="button" class="@(useVertices ? "on" : null)" aria-pressed="@(useVertices ? "true" : "false")" @onclick="() => useVertices = !useVertices">UseVertices</button>
    <button type="button" @onclick="Shuffle"><i class="astrol-flow-cross"></i> Shuffle</button>
</div>
<div style="height:440px">
    <AstrolBoard TBox="string" TRelation="object"
                 @ref="boardRef"
                 Board="board"
                 RelationAnchor="RelationAnchor.Border"
                 MinWidth="60" MinHeight="40">
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg); font-size:.85em">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
<style>
    .arrange-options {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        margin-bottom: 5px;
    }
 
        .arrange-options button {
            padding: 4px 12px;
            border-radius: 5px;
            border: 1px solid var(--color-gray-a);
            background: var(--layout-menu-bg);
            color: inherit;
            cursor: pointer;
        }
 
            .arrange-options button.on {
                background: var(--color-base);
                border-color: var(--color-base);
                color: var(--color-dark);
            }
</style>
 
@code {
    private AstrolBoard<string, object>? boardRef;
    private readonly Board<string, object> board = Create();
    private bool useVertices = true;
 
    private Task Arrange(BoardLayoutDirection direction) =>
        boardRef!.ArrangeAsync(new BoardLayoutOptions
        {
            Direction = direction,
            UseVertices = useVertices,
            LayerSpacing = 60,
            BoxSpacing = 30,
        });
 
    // Random positions and random vertices: a tangled board to arrange again.
    private void Shuffle()
    {
        var random = new Random();
        foreach (var box in board.Boxes)
        {
            box.X = 20 + random.Next(600);
            box.Y = 20 + random.Next(320);
        }
        foreach (var relation in board.Relations)
        {
            relation.Vertices = random.Next(3) == 0
                ? new List<Vertex> { new() { X = 20 + random.Next(600), Y = 20 + random.Next(320), Order = 1 } }
                : new List<Vertex>();
        }
    }
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        var names = new[] { "Request", "Validate", "Approve", "Reject", "Notify", "Pay", "Ship", "Invoice", "Close", "Audit", "Archive", "Help desk" };
        var random = new Random(3);
        foreach (var name in names)
        {
            b.Boxes.Add(new Box<string> { Id = name, X = 20 + random.Next(600), Y = 20 + random.Next(320), Width = 100, Height = 46, BOX_NAME = name, Content = "" });
        }
 
        void Link(string a, string c) => b.Relations.Add(new Relation<object> { BoxIdA = a, BoxIdB = c });
        Link("Request", "Validate");
        Link("Validate", "Approve");
        Link("Validate", "Reject");
        Link("Approve", "Pay");
        Link("Approve", "Notify");
        Link("Reject", "Notify");
        Link("Pay", "Ship");
        Link("Pay", "Invoice");
        Link("Ship", "Close");
        Link("Invoice", "Close");
        Link("Request", "Audit");    // long relation: it gets vertices
        Link("Close", "Archive");
        Link("Audit", "Archive");
        Link("Reject", "Request");   // cycle: it is drawn back up
        return b;
    }
}

7. Diapositivas tipo PowerPoint

Un editor de diapositivas: cada elemento (logo de AstrolUI en el color del tema, título, texto, lista, gráfica, forma) es una caja con cualquier contenido. Guías para alinear, límites de la diapositiva 16:9, doble clic para editar un texto, menús para insertar, ordenar y borrar, y una vista previa que pinta los mismos datos sin el tablero.
AstrolUI
Blazor components for .NET 10
Fast, light and accessible: a board, charts, a PDF viewer, a rich text editor and more.
  • Drag, resize and align with guides
  • Right-click to insert or order
  • Double-click a text to edit it
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI
@using Astrol.Entities.Basic.UI.Board
 
@* A slide editor in the style of PowerPoint: each element (image, title, text, list, chart, shape) is a box
   with any content. ShowGuides helps to align, MaxRight/MaxBottom keep everything inside the 16:9 slide,
   double-click edits a text and the menus insert, order and delete elements. "Preview" paints the same
   data without the board: the model is plain data you can save and show anywhere. *@
<div class="slide-toolbar">
    <button type="button" @onclick="() => Add(SlideKind.Title, 60, 60)"><i class="astrol-font"></i> Title</button>
    <button type="button" @onclick="() => Add(SlideKind.Text, 60, 160)"><i class="astrol-doc-text"></i> Text</button>
    <button type="button" @onclick="() => Add(SlideKind.Image, 500, 60)"><i class="astrol-picture"></i> Image</button>
    <button type="button" @onclick="() => Add(SlideKind.Chart, 500, 250)"><i class="astrol-chart-bar"></i> Chart</button>
    <button type="button" @onclick="() => Add(SlideKind.Shape, 360, 300)"><i class="astrol-target"></i> Shape</button>
    <button type="button" class="slide-preview-button" @onclick="() => preview = !preview">
        <i class="@(preview ? "astrol-edit" : "astrol-play")"></i> @(preview ? "Edit" : "Preview")
    </button>
</div>
 
@if (preview)
{
    <div class="slide-preview">
        <div class="slide-page">
            @foreach (var box in board.Boxes)
            {
                <div class="slide-item" style="@Position(box)">@Content(box)</div>
            }
        </div>
    </div>
}
else
{
    <div style="height:500px">
        <AstrolBoard TBox="SlideItem" TRelation="object"
                     Board="board"
                     CssClass="slide-board"
                     BackgroundType="BackgroundType.None"
                     ShowGuides="true"
                     ShowSearch="false"
                     ShowZoom="false"
                     AllowChangeScale="false"
                     MinLeft="20" MinTop="20" MaxRight="820" MaxBottom="470"
                     MinWidth="30" MinHeight="30"
                     ShowBoardContextMenu="true"
                     ShowBoxContextMenu="true"
                     OnOpenBoardContextMenu="p => { position = p; }"
                     OnOpenBoxContextMenu="e => { (boxId, position) = e; }"
                     OnDobleClickBox="b => { editingId = b.Content.Kind is SlideKind.Title or SlideKind.Text or SlideKind.List ? b.Id : null; }">
            <BoardContextMenu>
                <MenuOpion NeedAuthorize="false" Icon="astrol-font" Text="Insert title" OnClick="() => AddHere(SlideKind.Title)" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-doc-text" Text="Insert text" OnClick="() => AddHere(SlideKind.Text)" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-list-bullet" Text="Insert list" OnClick="() => AddHere(SlideKind.List)" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-picture" Text="Insert AstrolUI logo" OnClick="() => AddHere(SlideKind.Image)" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-chart-bar" Text="Insert chart" OnClick="() => AddHere(SlideKind.Chart)" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-target" Text="Insert shape" OnClick="() => AddHere(SlideKind.Shape)" />
            </BoardContextMenu>
            <BoxContextMenu>
                <MenuOpion NeedAuthorize="false" Icon="astrol-pencil" Text="Edit text (double-click)" Status="IsText" OnClick="() => editingId = boxId" HasSeparator="true" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-level-up" Text="Bring to front" OnClick="() => Order(true)" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-level-down" Text="Send to back" OnClick="() => Order(false)" HasSeparator="true" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-clone" Text="Duplicate" OnClick="Duplicate" />
                <MenuOpion NeedAuthorize="false" Icon="astrol-trash" IconColor="var(--aui-danger)" Text="Delete" OnClick="Delete" />
            </BoxContextMenu>
            <BoxRender>
                @if (editingId == context.Id)
                {
                    <textarea class="slide-editor slide-@context.Content.Kind.ToString().ToLowerInvariant()"
                              @bind="context.Content.Text"
                              @onblur="() => editingId = null"
                              @ref="editor"></textarea>
                }
                else
                {
                    @Content(context)
                }
            </BoxRender>
        </AstrolBoard>
    </div>
}
 
<style>
    .slide-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        margin-bottom: 5px;
    }
 
        .slide-toolbar button {
            padding: 4px 10px;
            border-radius: 5px;
            border: 1px solid var(--color-gray-a);
            background: var(--layout-menu-bg);
            color: inherit;
            cursor: pointer;
        }
 
    .slide-preview-button {
        margin-left: auto;
    }
 
    /* The 16:9 slide (800 x 450) inside the board */
    .slide-board .p-board-canvas::before {
        content: '';
        position: absolute;
        left: 20px;
        top: 20px;
        width: 800px;
        height: 450px;
        background: #fff;
        box-shadow: 0 4px 18px rgba(0, 0, 0, .25);
        border-radius: 4px;
        pointer-events: none;
    }
 
    .slide-board .p-box {
        color: #1d2330;
    }
 
    .slide-title {
        font-size: 1.9em;
        font-weight: 700;
        line-height: 1.1;
    }
 
    .slide-text {
        font-size: 1.1em;
        line-height: 1.4;
        color: #4a5160;
    }
 
    .slide-list {
        font-size: 1.1em;
        line-height: 1.6;
        margin: 0;
        padding-left: 1.3em;
    }
 
    .slide-editor {
        width: 100%;
        height: 100%;
        resize: none;
        border: 1px dashed var(--color-base);
        background: transparent;
        color: inherit;
        font-family: inherit;
        padding: 0;
    }
 
    .slide-chart {
        height: 100%;
        display: flex;
        align-items: flex-end;
        gap: 8%;
        padding: 0 4% 0;
        border-bottom: 2px solid #c9ced8;
        box-sizing: border-box;
    }
 
        .slide-chart div {
            flex: 1;
            border-radius: 4px 4px 0 0;
            background: linear-gradient(180deg, #ffc107, #ff8f00);
        }
 
    .slide-shape {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background: radial-gradient(circle at 30% 30%, #6fb6ff, #1565c0);
    }
 
    .slide-image {
        width: 100%;
        height: 100%;
        object-fit: contain;
        pointer-events: none;
    }
 
    .slide-preview {
        max-width: 100%;
        overflow: auto;
        padding: 10px;
    }
 
    /* Same coordinates as the board (without the 20px margin of the board) */
    .slide-page {
        position: relative;
        width: 800px;
        height: 450px;
        background: #fff;
        color: #1d2330;
        border-radius: 4px;
        box-shadow: 0 4px 18px rgba(0, 0, 0, .25);
        overflow: hidden;
        font-size: 15px;
    }
 
    .slide-item {
        position: absolute;
    }
</style>
 
@code {
    public enum SlideKind { Title, Text, List, Image, Chart, Shape }
 
    public sealed class SlideItem
    {
        public SlideKind Kind { get; set; }
        public string Text { get; set; } = "";
    }
 
    // The layout cascades the theme color: the logo follows it (logo-astrolui-yellow/green/blue/... .svg).
    [CascadingParameter(Name = "ThemeStyle")]
    public AstrolTheme Theme { get; set; }
 
    private string Logo => $"img/logos/logo-astrolui-{Theme.ToString().ToLowerInvariant()}.svg";
 
    private static readonly int[] Bars = { 35, 60, 45, 85, 70 };
 
    private readonly Board<SlideItem, object> board = Create();
    private Position position = new();
    private string? boxId;
    private string? editingId;
    private bool preview;
    private ElementReference editor;
    private string? focusedEditor;
 
    private bool IsText => board.Boxes.FirstOrDefault(b => b.Id == boxId)?.Content.Kind is SlideKind.Title or SlideKind.Text or SlideKind.List;
 
    private RenderFragment Content(Box<SlideItem> box) => __builder =>
    {
        switch (box.Content.Kind)
        {
            case SlideKind.Title:
                <div class="slide-title">@box.Content.Text</div>
                break;
            case SlideKind.Text:
                <div class="slide-text">@box.Content.Text</div>
                break;
            case SlideKind.List:
                <ul class="slide-list">
                    @foreach (var line in box.Content.Text.Split('\n', StringSplitOptions.RemoveEmptyEntries))
                    {
                        <li>@line</li>
                    }
                </ul>
                break;
            case SlideKind.Image:
                <img class="slide-image" src="@Logo" alt="AstrolUI" draggable="false" />
                break;
            case SlideKind.Chart:
                <div class="slide-chart">
                    @foreach (var bar in Bars)
                    {
                        <div style="height:@(bar)%"></div>
                    }
                </div>
                break;
            default:
                <div class="slide-shape"></div>
                break;
        }
    };
 
    private static string Position(Box<SlideItem> box) =>
        FormattableString.Invariant($"left:{box.X - 20}px; top:{box.Y - 20}px; width:{box.Width}px; height:{box.Height}px;");
 
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        // Focus the text editor once when it opens.
        if (editingId != null && focusedEditor != editingId)
        {
            focusedEditor = editingId;
            await editor.FocusAsync();
        }
        else if (editingId == null)
        {
            focusedEditor = null;
        }
    }
 
    private void AddHere(SlideKind kind) => Add(kind, position.X / board.Scale, position.Y / board.Scale);
 
    private void Add(SlideKind kind, float x, float y)
    {
        var (width, height, text) = kind switch
        {
            SlideKind.Title => (420F, 60F, "New title"),
            SlideKind.Text => (360F, 80F, "Double-click to edit this text."),
            SlideKind.List => (320F, 110F, "First point\nSecond point\nThird point"),
            SlideKind.Image => (240F, 100F, ""),
            SlideKind.Chart => (260F, 160F, ""),
            _ => (90F, 90F, ""),
        };
        board.Boxes.Add(new Box<SlideItem>
        {
            X = Math.Clamp(x, 20, 820 - width),
            Y = Math.Clamp(y, 20, 470 - height),
            Width = width,
            Height = height,
            BOX_NAME = kind.ToString(),
            Content = new SlideItem { Kind = kind, Text = text },
        });
    }
 
    // The last box of the list is painted on top.
    private void Order(bool front)
    {
        var box = board.Boxes.First(b => b.Id == boxId);
        board.Boxes.Remove(box);
        if (front)
        {
            board.Boxes.Add(box);
        }
        else
        {
            board.Boxes.Insert(0, box);
        }
    }
 
    private void Duplicate()
    {
        var source = board.Boxes.First(b => b.Id == boxId);
        board.Boxes.Add(new Box<SlideItem>
        {
            X = Math.Min(source.X + 20, 820 - source.Width),
            Y = Math.Min(source.Y + 20, 470 - source.Height),
            Width = source.Width,
            Height = source.Height,
            BOX_NAME = source.BOX_NAME,
            Content = new SlideItem { Kind = source.Content.Kind, Text = source.Content.Text },
        });
    }
 
    private void Delete() => board.Boxes.RemoveAll(b => b.Id == boxId);
 
    private static Board<SlideItem, object> Create()
    {
        var b = new Board<SlideItem, object>();
        void Item(SlideKind kind, float x, float y, float w, float h, string text = "") =>
            b.Boxes.Add(new Box<SlideItem>
            {
                X = x, Y = y, Width = w, Height = h,
                BOX_NAME = kind.ToString(),
                Content = new SlideItem { Kind = kind, Text = text },
            });
 
        Item(SlideKind.Shape, 700, 330, 110, 110);
        Item(SlideKind.Image, 50, 45, 260, 90);
        Item(SlideKind.Title, 50, 160, 460, 50, "Blazor components for .NET 10");
        Item(SlideKind.Text, 50, 220, 420, 60, "Fast, light and accessible: a board, charts, a PDF viewer, a rich text editor and more.");
        Item(SlideKind.List, 50, 300, 380, 110, "Drag, resize and align with guides\nRight-click to insert or order\nDouble-click a text to edit it");
        Item(SlideKind.Chart, 540, 140, 240, 170);
        return b;
    }
}

8. Guías al arrastrar

ShowGuides en el tablero y Box.ShowGuides por caja. Seleccione una caja y arrástrela o redimensiónela.
100%
Drag me
Me too
No guides
@using Astrol.Component.Board
@using Astrol.Component.Basic.Form
@using Astrol.Entities.Basic.UI.Board
 
@* ShowGuides draws guide lines from the selected box while you drag or resize it.
   Each box can override it with Box.ShowGuides (here "No guides" never shows them). *@
<div style="margin-bottom:5px">
    <AstrolCheckbox @bind-Value="showGuides" Text="ShowGuides" />
</div>
<div style="height:380px">
    <AstrolBoard TBox="string" TRelation="object"
                 Board="board"
                 ShowGuides="showGuides"
                 BackgroundType="BackgroundType.Grids">
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg)">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
@code {
    private bool showGuides = true;
    private readonly Board<string, object> board = Create();
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        b.Boxes.Add(new Box<string> { X = 60, Y = 60, Width = 140, Height = 90, BOX_NAME = "Drag me", Content = "" });
        b.Boxes.Add(new Box<string> { X = 300, Y = 170, Width = 140, Height = 90, BOX_NAME = "Me too", Content = "" });
        b.Boxes.Add(new Box<string> { X = 520, Y = 60, Width = 140, Height = 90, BOX_NAME = "No guides", Content = "", ShowGuides = false });
        return b;
    }
}

9. Relaciones, vértices y fondos

Relaciones con vértices arrastrables, una relación de una caja consigo misma, DiscontinueLine y los cuatro BackgroundType.
100%
Start
Review
End
@using Astrol.Component.Board
@using Astrol.Component.Basic.Form
@using Astrol.Entities.Basic.UI.Board
 
@* Relations go from center to center. Vertices (in Order) bend the line and can be dragged.
   A relation of a box with itself draws a loop. DiscontinueLine draws dashed lines. *@
<div style="margin-bottom:5px">
    <AstrolCheckbox @bind-Value="dashed" Text="DiscontinueLine" />
    <select @bind="background" aria-label="BackgroundType" style="margin-left:15px">
        @foreach (var type in Enum.GetValues<BackgroundType>())
        {
            <option value="@type">@type</option>
        }
    </select>
</div>
<div style="height:380px">
    <AstrolBoard TBox="string" TRelation="object"
                 Board="board"
                 DiscontinueLine="dashed"
                 BackgroundType="background">
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:50%; border:2px solid var(--color-base); background:var(--layout-menu-bg)">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
@code {
    private bool dashed;
    private BackgroundType background = BackgroundType.Quadrants;
    private readonly Board<string, object> board = Create();
 
    private static Board<string, object> Create()
    {
        var b = new Board<string, object>();
        var start = new Box<string> { X = 40, Y = 140, Width = 100, Height = 100, BOX_NAME = "Start", Content = "" };
        var review = new Box<string> { X = 330, Y = 40, Width = 100, Height = 100, BOX_NAME = "Review", Content = "" };
        var end = new Box<string> { X = 600, Y = 160, Width = 100, Height = 100, BOX_NAME = "End", Content = "" };
        b.Boxes.AddRange(new[] { start, review, end });
 
        b.Relations.Add(new Relation<object> { BoxIdA = start.Id, BoxIdB = review.Id });
        b.Relations.Add(new Relation<object>
        {
            BoxIdA = review.Id,
            BoxIdB = end.Id,
            Vertices = new List<Vertex> { new() { X = 520, Y = 60, Order = 1 }, new() { X = 560, Y = 120, Order = 2 } },
        });
        b.Relations.Add(new Relation<object>
        {
            BoxIdA = start.Id,
            BoxIdB = end.Id,
            Vertices = new List<Vertex> { new() { X = 330, Y = 320, Order = 1 } },
        });
        b.Relations.Add(new Relation<object> { BoxIdA = review.Id, BoxIdB = review.Id }); // loop
        return b;
    }
}

10. Historial (deshacer y rehacer)

UndoAsync, RedoAsync y GetHistoryInfo mediante @ref; las cajas añadidas por usted también se pueden deshacer.
State 1 / 1
100%
One
Two
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
@using Astrol.Component.Basic.Button
@using Astrol.Entities.Basic.UI
 
@* Every change (drag, resize, arrows, boxes added or removed by you) goes to the history.
   Ctrl+Z / Ctrl+Y, or UndoAsync / RedoAsync through @ref. LongMemory sets how many states are kept. *@
<div style="margin-bottom:5px">
    <AstrolButton Icon="astrol-ccw" Text="Undo" Style="AstrolStyle.Blue" Status="@info.CanUndo" OnClick="Undo" />
    <AstrolButton Icon="astrol-cw-1" Text="Redo" Style="AstrolStyle.Blue" Status="@info.CanRedo" OnClick="Redo" />
    <AstrolButton Icon="astrol-plus" Text="Add box" Style="AstrolStyle.Green" OnClick="AddBox" />
    <span style="margin-left:10px">State @(info.CurrentIndex + 1) / @info.TotalStates</span>
</div>
<div style="height:340px">
    <AstrolBoard @ref="boardRef"
                 TBox="string" TRelation="object"
                 Board="board"
                 LongMemory="20"
                 OnChangeBoard="_ => Refresh()">
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg)">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
@code {
    private AstrolBoard<string, object>? boardRef;
    private BoardHistoryInfo info = new();
    private readonly Board<string, object> board = new()
    {
        Boxes = new List<Box<string>>
        {
            new() { X = 40, Y = 40, Width = 130, Height = 80, BOX_NAME = "One", Content = "" },
            new() { X = 260, Y = 120, Width = 130, Height = 80, BOX_NAME = "Two", Content = "" },
        },
    };
 
    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender) Refresh();
    }
 
    private void Refresh()
    {
        info = boardRef?.GetHistoryInfo() ?? new BoardHistoryInfo();
        StateHasChanged();
    }
 
    private async Task Undo()
    {
        await boardRef!.UndoAsync();
        Refresh();
    }
 
    private async Task Redo()
    {
        await boardRef!.RedoAsync();
        Refresh();
    }
 
    private async Task AddBox()
    {
        board.Boxes.Add(new Box<string> { X = 40 + board.Boxes.Count * 30, Y = 230, Width = 130, Height = 80, BOX_NAME = $"Box {board.Boxes.Count + 1}", Content = "" });
        await Task.Yield(); // the board detects the new box on this render
        Refresh();
    }
}

11. Límites y tamaño mínimo

MinLeft, MinTop, MaxRight, MaxBottom, MinWidth y MinHeight (el área permitida se marca con una línea discontinua).
Inside
Also inside
@using Astrol.Component.Board
@using Astrol.Entities.Basic.UI.Board
 
@* Boxes can only move inside the area MinLeft-MaxRight / MinTop-MaxBottom (dashed) and cannot be smaller
   than MinWidth x MinHeight. The limits apply to the mouse, the arrows and the resize handles. *@
<div style="height:380px">
    <AstrolBoard TBox="string" TRelation="object"
                 Board="board"
                 CssClass="board-limits-area"
                 BackgroundType="BackgroundType.None"
                 ShowZoom="false"
                 MinLeft="20" MinTop="20" MaxRight="620" MaxBottom="320"
                 MinWidth="60" MinHeight="40">
        <BoxRender>
            <div style="height:100%; display:flex; align-items:center; justify-content:center; border-radius:8px; border:1px solid var(--color-gray-a); background:var(--layout-menu-bg)">
                @context.BOX_NAME
            </div>
        </BoxRender>
    </AstrolBoard>
</div>
 
<style>
    /* Only to show the limits in this example */
    .board-limits-area .p-board-canvas::before {
        content: '';
        position: absolute;
        left: 20px;
        top: 20px;
        width: 600px;
        height: 300px;
        border: 2px dashed var(--color-orange);
        border-radius: 8px;
        pointer-events: none;
    }
</style>
 
@code {
    private readonly Board<string, object> board = new()
    {
        Boxes = new List<Box<string>>
        {
            new() { X = 40, Y = 40, Width = 120, Height = 70, BOX_NAME = "Inside", Content = "" },
            new() { X = 400, Y = 200, Width = 160, Height = 90, BOX_NAME = "Also inside", Content = "" },
        },
    };
}
Markdown para IA © 2026 AstrolUI v10.0.13