-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
60 lines (49 loc) · 2.24 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using DevExpress.Diagram.Core;
using DevExpress.Utils.Serializing;
using DevExpress.Xpf.Diagram;
using System;
using System.Windows;
namespace WpfApp13 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
RegisterStencil();
}
void RegisterStencil() {
var stencil = new DiagramStencil("CustomStencil", "Custom Shapes");
RegularFactoryItemTool(stencil);
FactoryItemToolForCustomShape(stencil);
DiagramToolboxRegistrator.RegisterStencil(stencil);
diagramControl1.SelectedStencils = new StencilCollection() { "CustomStencil" };
}
public void RegularFactoryItemTool(DiagramStencil stencil) {
var itemTool = new FactoryItemTool("CustomShape1",
() => "Custom Shape 1",
diagram => new DiagramShape() { Content = "Predefined text" },
new System.Windows.Size(200, 200),
false
);
stencil.RegisterTool(itemTool);
}
public void FactoryItemToolForCustomShape(DiagramStencil stencil) {
DiagramControl.ItemTypeRegistrator.Register(typeof(DiagramShapeEx));
ResourceDictionary customShapesDictionary = new ResourceDictionary() { Source = new Uri("CustomShapes.xaml", UriKind.Relative) };
var invisibleStencil = DiagramStencil.Create("InvisibleStencil", "Invisible Stencil", customShapesDictionary, shapeName => shapeName, false);
DiagramToolboxRegistrator.RegisterStencil(invisibleStencil);
var itemTool = new FactoryItemTool("CustomShape2",
() => "Custom Shape 2",
diagram => new DiagramShapeEx() {
Shape = DiagramToolboxRegistrator.GetStencil("InvisibleStencil").GetShape("Shape1"),
CustomProperty = "Some value"
},
new System.Windows.Size(200, 200),
false
);
stencil.RegisterTool(itemTool);
}
}
public class DiagramShapeEx : DiagramShape {
[XtraSerializableProperty]
public string CustomProperty { get; set; }
}
}