Programmatically highlight vertices

Jan 5, 2010 at 6:16 PM

Dear all,

I am developing a program that shows a random walk on a graph.

When the walker enters a vertex, I want to highlight it.
When the walker leaves the vertex and enters the next vertex, I want to remove highlight from the first vertex, and highlight the next one.

Besides, user can click some vertices as targets.  If the random walker hit any one of those targets, the program ends.  Here I also want to set different styles to those target vertices.

I've tried the following,

            MyGraph g = new MyGraph();
            g.AddVerticesAndEdge(new MyEdge("hello", "world"));
            layout.Graph = g;
            layout.HighlightVertex(new MyVertex("world"), null);
            layout.RemoveHighlightFromVertex(new MyVertex("hello"));

I just couldn't figure out what to put as the second argument for HighlightVertex()

            layout.HighlightVertex(TVertex, object);           // object??  what type of object??

My second question is, can the highlighting change the shape, color and size??
For example, changing from a small green ellipse into a big red rectangle.  How can I do it??

Thank you in advance.  Happy new year!!!



Jan 6, 2010 at 3:00 PM

I figured out a little bit.

For the first argument, I should pass-in the original object instead of a new object (new MyVertex("world") is a new object).
Then, I found at least 4 different workable highlightings.

    layout.HighlightVertex(v, null);
    layout.SemiHighlightVertex(v, null);
    layout.SemiHighlightVertex(v, "Source");
    layout.SemiHighlightVertex(v, "Target");

At least I can use these 4 highlightings in my program, although I still don't know why they worked.
I wonder whether there are other choices available or not.  I am also curious about how to change vertex shapes dynamically.

Hope Graph# has some documentation.

Jan 8, 2010 at 8:01 AM

I figured out more.

I consulted "PocGraphDataTemplates.xaml" in the source code project, and copied the <Style TargetType="{x:Type GraphSharp_Controls:VertexControl}"> and all related resources into my <Window.Resources>

I created a MultiTrigger like this:

                        <Condition Property="GraphSharp_Controls:GraphElementBehaviour.IsSemiHighlighted" Value="True"/>
                        <Condition Property="GraphSharp_Controls:GraphElementBehaviour.SemiHighlightInfo" Value="BigRedRectangle"/>
                    <Setter Property="Template">
                            <ControlTemplate TargetType="{x:Type GraphSharp_Controls:VertexControl}">
                                <Rectangle Width="100" Height="100" Fill="Red" />

then I can change the shape of a vertex with layout.SemiHighlightVertex(v, "BigRedRectangle");

In some sense, source code project itself is a good documentation.