我正在使用WPF和Graph#库,尝试将图形绘制成线性链。因此,我定义了一些顶点以及连接它们的边:
new Edge<object>(vertices[i], vertices[i+1])
但问题是,生成的图形并不像预期那样绘制,结果是:
1 -> 2 -> 3 -> 1-> 4
换句话说,顶点3通过顶点1到达顶点4。
以下是绘图方法的代码
private void CreateGraphToVisualize()
{
var g = new BidirectionalGraph<object, IEdge<object>>();
// add the vertices to the graph
string[] vertices = new string[5];
for (int i = 0; i < 5; i++)
{
vertices[i] = i.ToString();
g.AddVertex(vertices[i]);
}
// add edges to the graph
g.AddEdge(new Edge<object>(vertices[0], vertices[1]));
g.AddEdge(new Edge<object>(vertices[1], vertices[2]));
g.AddEdge(new Edge<object>(vertices[2], vertices[3]));
g.AddEdge(new Edge<object>(vertices[3], vertices[4]));
GraphToVisualize = g;
}
这里是与graph#相关的XAML代码的一部分。
<DockPanel Grid.Row="2" Margin="10,10,13,10">
<zoom:ZoomControl>
<graphsharp:GraphLayout x:Name="graphLayout"
Graph="{Binding ElementName=root,Path=GraphToVisualize}"
LayoutAlgorithmType="FR"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"/>
</zoom:ZoomControl>
</DockPanel>
0 -> 1 -> 2 -> 3 -> 4
。 - Alex Humphrey