Debugging Suggestions

Developing a diagramming app involves a lot more than just writing some C# code that uses the GoDiagram library.

  • You will need to be familiar with your chosen platform.
  • You will need to know how to use the console and debugger.

Use debug mode

While developing your app make sure you use debug mode by setting Diagram.Debug = true. Debug mode does more error checking of property values and method arguments, and it detects more unusual situations. Most warning and errors will be written to the output window. Always check it for messages. We have tried to make them informative.

Use the documented API

If you want to modify the behavior of the GoDiagram classes, the proper way is via the techniques discussed at Extensions. However most of the GoDiagram classes cannot be subclassed and most of the documented methods cannot be overridden. Generally the Tool and Layout classes and the CommandHandler and Link classes may be subclassed; look at the API documentation to see if a method may be overridden.

Using the debugger

First you will need to get a reference to your Diagram object in the debugging window.

One way to do that is by remembering it in your code. You can set a static property on the class to refer to the Diagram that you create.

myDiagram = diagramControl1.Diagram;

Then you'll need a breakpoint in your code. You can either set one in your IDE, or add one via System.Diagnostics.Debugger.Break(); You can then examine various properties of the Diagram via Autos, Locals, and watches. Also, in the immediate window you can use the myDiagram reference to the Diagram object. Some examples:

myDiagram.Nodes.Count
returns the number of Nodes in the Diagram.

myDiagram.Model.NodeDataSource.First()
returns the first node data object in the diagram's model's Model.NodeDataSource.

myDiagram.LayoutDiagram(true)
forces all layouts to happen, rearranging the nodes and routing the links.

Examining a selected Node

myDiagram.Selection.FirstOrDefault()
returns the first selected Part, which might be either a Node, a Link, or null if nothing is selected.

If you remember the selected Node or Link, you can then examine it further more easily. For example:


var myNode = myDiagram.Selection.FirstOrDefault()
(myNode.Data as NodeData).Key
      
remembers the first selected Node and returns the key of the node data. You might want to look at all of the properties of the
myNode.Data
object.

You could also look at other properties of the Node and call some of its methods. For example:

myNode.Location
returns a Point whose properties the debugger may show. Or call:
myNode.Location.ToString()
to see a human-readable textual rendering of that Point object.

As another example, you can see all of the nodes the selected node is connected to:

myNode.FindNodesOutOf()

Debugging Node Panel designs

When building your own node template, there may be times when the objects in the node are not sized and positioned the way that you would like. It is important that you understand how objects may be assembled within panels. You will want to re-read:

One common way of debugging issues with templates is to set GraphObject.Background. This can make it easier to identify sizing and positioning problems.


myDiagram.NodeTemplate =
  new Node("Auto") { Background = "red" }
    .Add(
      new Shape("RoundedRectangle")
        .Bind("Fill", "Color"),
      new TextBlock { Background = "lime" }
        .Bind("Text")
    );
      
In this case, it's simpler to see how large the TextBlock really is and what the true bounds of the Node are.