I'm using a TableNode with an AnchorPattern specified on each row. I want to be able to add/remove rows from the TableNode dynamically. This works well except when I try to delete the last row in the TableNode. It appears to work fine, but the next time the TableNode is moused-over, an exception is thrown.
Here's the exception stack trace:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at MindFusion.Diagramming.Wpf.TableNode.CellCollection.get_Item(Int32 index)
at MindFusion.Diagramming.Wpf.TableNode.get_Item(Int32 col, Int32 row)
at MindFusion.Diagramming.Wpf.TableNode.x3d2277a3b84b3698(AnchorPoint x1bf64e6273c3575c, Visibility x9b4602d5e4f04fcb)
at MindFusion.Diagramming.Wpf.DiagramNode.x3d2277a3b84b3698(DiagramNode x8d5eca828b99d00c)
at MindFusion.Diagramming.Wpf.DiagramNode.x3d2277a3b84b3698()
at MindFusion.Diagramming.Wpf.Diagram.x92bb101faf551658(DiagramNode xda5bf54deb817e37)
at MindFusion.Diagramming.Wpf.Diagram.xc9ce7799411b196f(Point x70c02b32ea858ee7)
at MindFusion.Diagramming.Wpf.Diagram.OnPreviewMouseMove(MouseEventArgs e)
Here is the simple code to replicate this problem:
AnchorPattern anchorPattern = new AnchorPattern(
new[]
{
new AnchorPoint(50, 50, true, false, Brushes.Green, 0){MarkStyle = MarkStyle.Custom},
});
// defaults to 4 rows and 2 columns
TableNode tableNode = new TableNode();
tableNode.Rows[0].AnchorPattern = anchorPattern;
tableNode.Rows[1].AnchorPattern = anchorPattern;
tableNode.Rows[2].AnchorPattern = anchorPattern;
tableNode.Rows[3].AnchorPattern = anchorPattern;
Diagram.Nodes.Add(tableNode);
tableNode.DeleteRow(3);
I've noticed that the exception only occurs when using an AnchorPattern that uses a specific column in the row. If I set the Column property back to the default value of -1 right before deleting, the exception is not thrown.
Like this:
tableNode.Rows[3].AnchorPattern.Points[0].Column = -1;
tableNode.DeleteRow(3);
That is a bad hack though, as we have different AnchorPatterns that could be used with varying numbers of points. Plus other odd things start happening with the adding/removing of other rows.