我尝试使用 CodePlex 的 GraphSharp 创建一棵树。
我查看了示例应用程序并尝试“重新设计”该示例。
问题是,如果我尝试以编程方式设置 LayoutAlgorithmType = "Tree",我会得到一个 TargetInvocationException ......这很神秘,因为在示例中它可以工作。
我的问题是:如何创建具有树布局和从左到右方向的图形。
提前致谢 :)
我的代码:
public partial class MainWindow : Window
{
private IBidirectionalGraph<object, IEdge<object>> _graphToVisualize;
public IBidirectionalGraph<object, IEdge<object>> GraphToVisualize
{
get { return _graphToVisualize; }
}
public MainWindow()
{
CreateGraphToVisualize();
InitializeComponent();
}
private void CreateGraphToVisualize()
{
var g = new BidirectionalGraph<object, IEdge<object>>();
string[] vs = new string[5];
for (int i = 0; i < 5; i++)
{
vs[i] = i.ToString();
g.AddVertex(vs[i]);
}
//add some edges
g.AddEdge(new Edge<object>(vs[0], vs[1]));
g.AddEdge(new Edge<object>(vs[0], vs[2]));
g.AddEdge(new Edge<object>(vs[2], vs[3]));
g.AddEdge(new Edge<object>(vs[1], vs[4]));
g.AddEdge(new Edge<object>(vs[3], vs[4]));
layout.LayoutMode = LayoutMode.Automatic;
layout.LayoutAlgorithmType = "Tree";
_graphToVisualize = g;
}
}
xml:
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:GraphSharp_Controls="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:graph="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:Controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
Title="MainWindow" Height="350" Width="525"
x:Name="root">
<Grid>
<Controls:ZoomControl>
<graph:GraphLayout x:Name="layout" />
</Controls:ZoomControl>
</Grid>
</Window>