简体   繁体   中英

Sample for using Graph# in Winforms

Can anyone point me to an example of how to use Graph# via ElementHost in a winforms application (c#).

Especially loading *.gml - files and showing the Graph-control.

Any help appreciated .

The basic idea is to create a WPF user control, that encapsulates a Graph # canvas. This user control is what you would then display in the ElementHost.

I have put together a small sample application that demonstrates this by basically exposing the GraphSharp.Sample.TestCompoundLayout window as user control.

http://cl.ly/0w350230200g0w0o2R2N

I also added loading from GML files which basically boils down to this function:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM