ralf.w.
ralf.w.

Reputation: 1696

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.

Upvotes: 8

Views: 5061

Answers (1)

Frank
Frank

Reputation: 1132

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

Upvotes: 6

Related Questions