C# GraphX highlight vertex on click

459 views Asked by At

I'm using GraphX for .NET and I'm trying to highlight a vertex when the user clicks on it.

I registered for the VertexSelected event:

public class MyGraphArea : GraphArea<Node, Edge, MiniFlowGraph>
{
    public MyGraphArea()
    {
        VertexSelected += VertexSelected_MarkVertex;
    }

    private void VertexSelected_MarkVertex(object sender,VertexSelectedEventArgs args)
    {
        HighlightBehaviour.SetHighlighted(args.VertexControl, true);
    }
}

But nothing happened in the UI. So I tried to add multiple options:

To the constructor I added:

EnableVisualPropsApply = true;
HighlightBehaviour.SetIsHighlightEnabled(this, true);
SetVerticesHighlight(true, GraphControlType.VertexAndEdge);

I also registered to the Loaded event and added this code:

foreach (var item in VertexList)
    HighlightBehaviour.SetIsHighlightEnabled(item.Value, true);

Then I added the line SetVerticesHighlight(true, GraphControlType.VertexAndEdge) to the VertexSelected event, just for case.

But nothing happened.

I'm looking at the source code, and I can't find anything else.

1

There are 1 answers

0
sɐunıɔןɐqɐp On

I believe you just need to add the following lines of code:

Graph.SetEdgesHighlight(true, GraphControlType.VertexAndEdge);
Graph.SetVerticesHighlight(true, GraphControlType.VertexAndEdge, EdgesType.All);

I was playing around with the WindowsFormsProject example, and I added these lines just before the return statement of the method Form1.GenerateWpfVisuals(). I did not had to subscribe to any event. However, the standard behavior will highlight vertices and edges on mouse hover, not on mouse click.

The default Gold color is used for the highlighting is defined in template.xaml:

<!-- VERTEX CONTROL -->
...
    <Style.Triggers>
        <Trigger Property="controls:HighlightBehaviour.Highlighted" Value="True">
            <Setter Property="Background" Value="Gold"/>
            <Setter Property="BorderThickness" Value="7"/>
        </Trigger>
    </Style.Triggers>

...

<!-- EDGE CONTROL -->
...
    <Style.Triggers>
        <Trigger Property="controls:HighlightBehaviour.Highlighted" Value="True">
            <Setter Property="Foreground" Value="Gold"/>
            <Setter Property="StrokeThickness" Value="5"/>
        </Trigger>
    </Style.Triggers>