Search code examples
c#winformsxaml

How to set the Edge label in GraphX


I am using GraphX in Winform project. I am trying to display labels besides the edges. I want to know what property do I have to set in order to display some text in the label.

I have tried setting the 'Text' property of DataEdge, and then calling

ShowAllEdgesLabels(true);

but it does not work this way. Going through the forums I have found that WPF has a way to bind this property to the visual control. The XAML code is as follows

<gxl:EdgeLabelControl x:Name="PART_edgeLabel" Content="{Binding Edge.Text, RelativeSource={RelativeSource TemplatedParent}}" />

Now the question is what is the equivalent of Winform to achieve this functionality.


Solution

  • I found a solution with the help of the admin at the host of GraphX (PantheR).

    Basically, we need to add the hostControler for WPF in a windows form. We need to add a custom XAML template in the resources folder. We need to load the XAML as a new resource in the code, before we initialize the graph. We need to add a line of code to merge the resources.

    Then in the XAML code we do the binding as mentioned in the question. The code has been updated at the repository to reflect these changes.

    The downfall of this solution is that, we need to provide a XAML resource file with the program, but thats just another resource (in my opinion).