void CreateToolboxItems(string path) { var stencil = new DevExpress.Diagram.Core.DiagramStencil("SVGStencil", "IcoMoon - Free Shapes"); string name = string.Empty; foreach (string file in Directory.GetFiles(path)) { try { name = System.IO.Path.GetFileNameWithoutExtension(file); using (FileStream stream = File.Open(file, FileMode.Open)) { var shape = DevExpress.Diagram.Core.ShapeDescription.CreateSvgShape(name, name, stream) .Update(getDefaultSize: () => new System.Windows.Size(100, 100)) .Update(getConnectionPoints: (w, h, p) => new[] { new System.Windows.Point(w / 2, h / 2) }); stencil.RegisterShape(shape); } } catch (Exception) { //some SVG files cannot be parsed, so swallow the exception for now. //throw; } } DevExpress.Diagram.Core.DiagramToolboxRegistrator.RegisterStencil(stencil); diagramDesignerControl1.SelectedStencils.Add("SVGStencil"); diagramDesignerControl1.Items.Add(new DiagramShape() { Shape = stencil.GetShape("aid-kit"), Width = 100, Height = 100, Position = new Point(300, 300) }); }
void RegisterStencil() { var stencil = new DevExpress.Diagram.Core.DiagramStencil("CustomStencil", "Custom Shapes"); var itemTool = new FactoryItemTool("CustomShape", () => "Custom Shape", diagram => { DiagramShapeEx customShape = new DiagramShapeEx() { Width = 100, Height = 50 }; return(customShape); }, new System.Windows.Size(100, 50), false); stencil.RegisterTool(itemTool); DevExpress.Diagram.Core.DiagramToolboxRegistrator.RegisterStencil(stencil); DiagramControl.ItemTypeRegistrator.Register(typeof(DiagramShapeEx)); }