这张图片显示了项目的作用
我可以像这样将画布保存到 xml:
private void SaveFile(object sender, RoutedEventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog()
{
DefaultExt = "xml",
Filter = "XML Files (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
if (saveFileDialog.ShowDialog() == true)
{
using (Stream stream = saveFileDialog.OpenFile())
{
using (StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8))
{
sw.Write(GetGeneratedXML().ToString());
}
}
}
}
private XElement GetGeneratedXML()
{
XElement userInformation = new XElement("Diagrama");
foreach (MyBox b in boxes)
{
userInformation.Add(new XElement("Entidade",
new XElement("Nome", b.Header),
new XElement("Atributo", b.Text)));
}
foreach (Connection1 c in connections)
{
userInformation.Add(new XElement("Relação",
new XElement("Entidade1",
new XAttribute("Nome", c.Box1.Header),
new XAttribute("Cardinalidade", c.Node1.Title)),
new XElement("Entidade2",
new XAttribute("Nome", c.Box2.Header),
new XAttribute("Cardinalidade", c.Node2.Title)
)
)
);
}
return userInformation;
}
现在,我想导入这个 XML 文件,然后用框和连接更新画布。有任何想法吗?