Hi !
I would like to know how to save/load StrokeDashArray property from xml…Steps that I did, and I can´t see StrokeDashArray:
Thanks!
Step 1: Changed FlowChart.xml file:
Step 2: Changed MyNodeData class
//The data class representing nodes.
public class MyNodeData : GraphLinksModelNodeData
{
// The shape of each node
public NodeFigure Figure
{
get { return _Figure; }
set
{
if (_Figure != value)
{
NodeFigure old = _Figure;
_Figure = value;
RaisePropertyChanged(“Figure”, old, value);
}
}
}
private NodeFigure _Figure = NodeFigure.Rectangle;
public int StrokeDashArray
{
get { return _StrokeDashArray; }
set
{
int old = _StrokeDashArray;
if (old != value)
{
_StrokeDashArray = value;
RaisePropertyChanged("StrokeDashArray", old, value);
}
}
}
private int _StrokeDashArray = 2;
// note that adding properties here means also adding lines to MakeXElement and LoadFromXElement
public override XElement MakeXElement(XName n)
{
XElement e = base.MakeXElement(n);
e.Add(XHelper.AttributeEnum<NodeFigure>("Figure", this.Figure, NodeFigure.Rectangle));
e.Add(XHelper.Attribute("StrokeDashArray", this.StrokeDashArray, 2));
return e;
}
public override void LoadFromXElement(XElement e)
{
base.LoadFromXElement(e);
this.Figure = XHelper.ReadEnum<NodeFigure>("Figure", e, NodeFigure.Rectangle);
this.StrokeDashArray = XHelper.Read("StrokeDashArray", e, 2);
}
}
Step 3: Changed palette’s model’s data
// set up the model for the Palette
var paletteModel = new GraphLinksModel<MyNodeData, String, String, MyLinkData>();
// this creates the palette's model's data in code:
paletteModel.NodesSource = new List<MyNodeData>() {
new MyNodeData() { Key="Comment", Text="Comment", Category="Comment", Figure=NodeFigure.Rectangle, StrokeDashArray=2 },
new MyNodeData() { Key="Start", Text="Start", Category="Start", Figure=NodeFigure.RoundedRectangle,StrokeDashArray=2 },
new MyNodeData() { Key="Step", Text="Step", Category="Standard", Figure=NodeFigure.Rectangle, StrokeDashArray=2 },
new MyNodeData() { Key="Input", Text="Input", Category="Standard", Figure=NodeFigure.Input, StrokeDashArray=2 },
new MyNodeData() { Key="Output", Text="Output", Category="Standard", Figure=NodeFigure.Output, StrokeDashArray=2 },
new MyNodeData() { Key="Conditional", Text="?", Category="Standard", Figure=NodeFigure.Diamond, StrokeDashArray=2 },
new MyNodeData() { Key="Read", Text="Read", Category="Standard", Figure=NodeFigure.Ellipse , StrokeDashArray=2},
new MyNodeData() { Key="Write", Text="Write", Category="Standard", Figure=NodeFigure.Ellipse, StrokeDashArray=2 },
new MyNodeData() { Key="ManualOperation", Text="Manual Operation", Category="Standard", Figure=NodeFigure.ManualOperation, StrokeDashArray=2 },
new MyNodeData() { Key="DataBase", Text="DataBase", Category="Standard", Figure=NodeFigure.Database, StrokeDashArray=2 },
new MyNodeData() { Key="End", Text="End", Category="End", Figure=NodeFigure.RoundedRectangle, StrokeDashArray=2 }
};
myPalette.Model = paletteModel;
// set up an initial model for the Diagram
var model = new GraphLinksModel<MyNodeData, String, String, MyLinkData>();
// and initialize it from the XML file that is an embedded resource
String xml = WpfApplication1.MainWindow.Instance.LoadText("FlowChart", "xml");
model.Load<MyNodeData, MyLinkData>(XElement.Parse(xml), "MyNodeData", "MyLinkData");
model.Modifiable = true;
model.HasUndoManager = true;
myDiagram.Model = model;
Step 4: Changed DataTemplate: x:Key=“LinkTemplate” in XAML file, inserted: StrokeDashArray="{Binding Path=Data.StrokeDashArray}"