Back to Devexpress

DiagramStencil.RegisterShape(ShapeDescriptionBase) Method

corelibraries-devexpress-dot-diagram-dot-core-dot-diagramstencil-dot-registershape-x28-devexpress-dot-diagram-dot-core-dot-shapedescriptionbase-x29.md

latest5.4 KB
Original Source

DiagramStencil.RegisterShape(ShapeDescriptionBase) Method

Adds the specified shape to the stencil.

Namespace : DevExpress.Diagram.Core

Assembly : DevExpress.Diagram.v25.2.Core.dll

NuGet Package : DevExpress.Diagram.Core

Declaration

csharp
public void RegisterShape(
    ShapeDescriptionBase shape
)
vb
Public Sub RegisterShape(
    shape As ShapeDescriptionBase
)

Parameters

NameTypeDescription
shapeShapeDescriptionBase

A ShapeDescriptionBase descendant representing the shape to add to the stencil.

|

Remarks

The example below illustrates how to add an SVG shape to a stencil.

csharp
//create or get the stencil you want to add your SVG to
    var stencil = DiagramToolboxRegistrator.GetStencil("SvgShapes");

    //open the file here
    using (Stream file = File.OpenRead(filePathToSVGFile)) {
        String id = "SVGid";
        String name = "SVGname";

        //create your shapeDescription with the SVG
        var shapeDescription = ShapeDescription.CreateSvgShape(id, name, file, false);

        //add the shapeDescription to your stencil
        stencil.RegisterShape(shapeDescription);
    }
vb
'create or get the stencil you want to add your SVG to
    Dim stencil = DiagramToolboxRegistrator.GetStencil("SvgShapes")

    'open the file here
    Using file As Stream = System.IO.File.OpenRead(filePathToSVGFile)
        Dim id As String = "SVGid"
        Dim name As String = "SVGname"

        'create your shapeDescription with the SVG
        Dim shapeDescription = ShapeDescription.CreateSvgShape(id, name, file, False)

        'add the shapeDescription to your stencil
        stencil.RegisterShape(shapeDescription)
    End Using

To register custom diagram items, use the DiagramStencil.RegisterTool method.

The following code snippets (auto-collected from DevExpress Examples) contain references to the RegisterShape(ShapeDescriptionBase) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-diagram-register-and-use-svg-shapes/CS/DiagramSVGItemsWpf/MainWindow.xaml.cs#L25

csharp
.Update(getConnectionPoints: (w, h, p) => new[] { new Point(w / 2, h / 2) });
    stencil.RegisterShape(shape);
}

how-to-register-and-use-svg-shapes-t478182/CS/DiagramSVGItemsWinForms/Form1.cs#L39

csharp
.Update(getConnectionPoints: (w, h, p) => new[] { new System.Windows.Point(w / 2, h / 2) });
    stencil.RegisterShape(shape);
}

wpf-diagram-register-and-use-svg-shapes/VB/DiagramSVGItemsWpf/MainWindow.xaml.vb#L43

vb
Dim shape = DevExpress.Diagram.Core.ShapeDescription.CreateSvgShape(name_Renamed, name_Renamed, stream).Update(getDefaultSize:= Function() New System.Windows.Size(100, 100)).Update(getConnectionPoints:= Function(w, h, p) { New System.Windows.Point(w / 2, h / 2) })
    stencil.RegisterShape(shape)
End Using

how-to-register-and-use-svg-shapes-t478182/VB/DiagramSVGItemsWinForms/Form1.vb#L34

vb
Dim shape = DevExpress.Diagram.Core.ShapeDescription.CreateSvgShape(name_Renamed, name_Renamed, stream).Update(getDefaultSize:= Function() New System.Windows.Size(100, 100)).Update(getConnectionPoints:= Function(w, h, p) { New System.Windows.Point(w / 2, h / 2) })
    stencil.RegisterShape(shape)
End Using

See Also

UnregisterShape(ShapeDescriptionBase)

Shapes

DiagramStencil Class

DiagramStencil Members

DevExpress.Diagram.Core Namespace