在Winforms中使用Graph#的示例

本文关键字:Graph# Winforms | 更新日期: 2023-09-27 17:59:25

有人能给我举一个如何在winforms应用程序(c#)中通过ElementHost使用Graph#的例子吗。

特别是加载*.gml文件并显示Graph控件。

感谢任何帮助

在Winforms中使用Graph#的示例

基本思想是创建一个WPF用户控件,该控件封装了Graph#画布。这个用户控件就是您将在ElementHost中显示的内容。

我制作了一个小示例应用程序,通过基本上将GraphSharp.sample.TestComponentLayout窗口公开为用户控件来演示这一点。

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();