When I save a diagram with custom shapes to a string, and load the diagram from that string, the custom shapes appear as rounded rectangles instead of their original shape. I have put together a simple test program to illustrate the issue:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<diag:TabbedDiagramView Name="diag" Grid.Row="1" />
<Button Name="Load" Height="50" Click="AddCustomShape" HorizontalAlignment="Left">
Add Custom Shape
</Button>
<Button Name="Save" Height="50" Click="ReloadDocument" HorizontalAlignment="Center">
Reload the document
</Button>
</Grid>
public MainWindow()
{
InitializeComponent();
//Diagram.RegisterItemClass(typeof(DiagramCustomNode), "my:DiagramCustomNode", 1);
diag.Document = new DiagramDocument();
}
private void AddCustomShape(object sender, System.Windows.RoutedEventArgs e)
{
string xml = "<Shape id=\"Monitor\" fill-mode=\"Winding\"> <outline> <round-rectangle dash-style=\"Solid\" width=\"-1\" x=\"14\" y=\"8.25\" w=\"76.5\" h=\"63\" r=\"5\" /> </outline> <decorations> <round-rectangle dash-style=\"Solid\" width=\"-1\" x=\"20\" y=\"14.75\" w=\"63.5\" h=\"48\" r=\"5\" /> <round-rectangle dash-style=\"Solid\" width=\"-1\" x=\"39\" y=\"74.75\" w=\"29.5\" h=\"13\" r=\"5\" /> </decorations> <shape-decorations /></Shape>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
Shape s = new Shape(new byte[] { 0, 0, 1, 1, 2, 2 });
if (diag.Document == null)
diag.Document = new DiagramDocument();
if (diag.Document.Pages.Count == 0)
diag.Document.Pages.Add(new DiagramPage());
s.LoadFromXml(doc.ChildNodes[0] as XmlElement, new XmlPersistContext(diag.Document.Pages[0], doc, 1));
diag.Document.Pages[0].Items.Add(new ShapeNode() { Shape = s });
}
private void ReloadDocument(object sender, RoutedEventArgs e)
{
string s = diag.Document.SaveToString();
diag.Document.LoadFromString(s);
}
The first method, adding a custom shape originally created in the shape designer, works fine. It's the symbol for a computer monitor. Click the first button as often as you want and spread out the nodes. Reloading the document, however, turns all the monitor shapes into round rectangles.