Hi,
I have some nodes that are linked with themselves (link source and target is the same). Looks fine, but when after save them I try to load them... a exception happens.
I get the follow exception:
System.IndexOutOfRangeException occurred
Message="Index was outside the bounds of the array."
Source="MindFusion.Diagramming.Wpf"
StackTrace:
at MindFusion.x09d6340d05b7af69.xd2546c282e6f199a(DrawingContext x41347a961b838962, Pen x9c79b5ad7b769b12, Point[] x6fa2570084b2ad39)
InnerException:
I'm trying to save and retrieve the links from a XML. It was something that I thought was working but seems like the links never remains in the same position, so I did some changes in the code following your recommendations in other posts about UpdateFromPoints and SegmentCount, but I get that exeption.
I save the links with this code:
XElement linksXml = new XElement( "Links",
from l in DatabaseDiagram.Links.OfType<DiagramLink>().Where(l=>l.Tag is DataDiagramRelation)
select new XElement( "Link",
new XAttribute( "FkColumn", ((DataDiagramRelation)l.Tag).FkColumn ),
new XAttribute( "FromTableName", ((DataTable)l.Origin.Tag).TableName ),
new XAttribute( "ToTableName", ((DataTable)l.Destination.Tag).TableName),
new XAttribute( "LinkStyle", l.Style.ToString() ),
new XAttribute( "Color", "Black" ),
new XAttribute( "LinkHeader", l.HeadShape.ToString() ),
new XElement( "ControlPoints",
new XAttribute( "SegmentCount", l.SegmentCount ),
from p in l.ControlPoints.OfType<Point>()
select new XElement( "Point",
new XAttribute( "X", p.X ),
new XAttribute( "Y", p.Y ) ) )
And I obtain a XML, where one of the items is:
<Link FkColumn="ParentTaskId" FromTableName="table1" ToTableName="table1" LinkStyle="Cascading" Color="Black" LinkHeader="Reversed">
<ControlPoints SegmentCount="3">
<Point X="360" Y="109.99999999999996" />
<Point X="360" Y="110" />
<Point X="360" Y="110" />
<Point X="360" Y="109.99999999999996" />
</ControlPoints>
</Link>
Then, when I open the diagram again, I try to apply that configuratio to the links using the following code:
private void SetLinkProperties( XElement xlink, DiagramLink link )
{
Object style = Enum.Parse( typeof( LinkStyle ), xlink.Attribute( "LinkStyle" ).Value );
link.Style = style != null ? (LinkStyle)style : LinkStyle.Polyline;
Object header = Enum.Parse( typeof( ArrowHead ), xlink.Attribute( "LinkHeader" ).Value );
link.HeadShape = header != null ? (ArrowHead)header : ArrowHead.None;
if ( xlink.Attribute( "Color" ) != null )
{
link.Brush = GetSolidColorBrush( (String)xlink.Attribute( "Color" ) );
link.Pen = new Pen( link.Brush, 1 );
}
link.ControlPoints.Clear();
link.SegmentCount = Int16.Parse( xlink.Element( "ControlPoints" ).Attribute( "SegmentCount" ).Value );
foreach ( XElement controlPoint in xlink.Element( "ControlPoints" ).Descendants( "Point" ) )
link.ControlPoints.Add( new Point( Double.Parse( controlPoint.Attribute( "X" ).Value ),
Double.Parse( controlPoint.Attribute( "Y" ).Value ) ) );
link.UpdateFromPoints();
link.AutoRoute = true;
}
Then fails firstly on the "link.UpdateFromPoints();" line. The "link.ControlPoints" collection has 14 elements... although I only have added 4, I dunno if it's normal or not
Although I catch the exception, is raised again when I do "myForm.ShowDialog()" the the application crash.
Besides, the rest of the links are not keeping their exact locations.
What could be the problem?
Cheers.