最佳答案
基本思想是创建一个 WPF 用户控件,它封装了一个 Graph # canvas。此用户控件是您随后将在 ElementHost 中显示的内容。
我整理了一个小型示例应用程序,它基本上通过将 GraphSharp.Sample.TestCompoundLayout 窗口公开为用户控件来演示这一点。
http://cl.ly/0w350230200g0w0o2R2N
我还添加了从 GML 文件加载,基本上可以归结为这个函数:
var graph = new CompoundGraph<object, IEdge<object>>();
try
{
//open the file of the graph
var reader = XmlReader.Create(fileName);
//create the serializer
var serializer = new GraphMLDeserializer<object, IEdge<object>, CompoundGraph<object, IEdge<object>>>();
//deserialize the graph
serializer.Deserialize(reader, graph,
id => id, (source, target, id) => new Edge<object>(source, target)
);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
layout.Graph = graph;
layout.UpdateLayout();
关于c# - 在 Winforms 中使用 Graph# 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377347/