How to: Create Custom Diagram Containers and Register them in the Toolbox and Ribbon Gallery

  • 4 minutes to read

In this example, we show how to create containers with custom headers and padding. DiagramControl supports a special language for defining containers. The root element that contains a container description is ContainerShapeTemplate. This element describes a container contour and may contain several segments:- Start. Specifies the start point- Line. Defines a line with start and end points- Arc. Defines an arc with start and end pointsTo define a container's header editor position, use the EditorBounds property. To specify a padding, set the ActualPadding property.To register custom containers in the ribbon gallery, use the DiagramContainerGalleryRegistrator.RegisterContainerShapes method.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Diagram.Core;
using DevExpress.Diagram.Core.Shapes;
using System.Windows;
using System.IO;
using System.Reflection;

namespace XtraDiagram.CreateCustomContainers {
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm {
        const string MyContainersStencilName = "MyContainers";
        static readonly ContainerShapeDescription[] containerDescriptions;
        static Form1() {
            using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("XtraDiagram.CreateCustomContainers.CustomContainers.xml")) {
                containerDescriptions = ShapeDescriptions.LoadDescriptionsFromXml(stream).OfType<ContainerShapeDescription>().ToArray();
        public Form1() {
            var customContainersStencil = DiagramStencil.Create(MyContainersStencilName, "Custom Containers", containerDescriptions);
            diagramControl1.OptionsBehavior.Stencils = new DiagramStencilCollection(DiagramToolboxRegistrator.Stencils.Concat(new[] { customContainersStencil }));
            diagramControl1.SelectedStencils = new StencilCollection(MyContainersStencilName, BasicShapes.StencilId);
        protected override void OnLoad(EventArgs e) {