我正在将 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>