This project is read-only.

Custom Edge Class

Oct 5, 2009 at 4:42 PM

Can some post a short example on how to build a custom edge class ?

What I need to accomplish is to add a label/textblock next to every edge specifying the kind of relationship.

Thanks

Oct 6, 2009 at 1:59 AM

The first step would be to define your edge view model class (the one that you need to make part of your BidirectionalGraph-inheriting class) to have a property (and implement INotifyPropertyChanged if necessary) that represents the data you'd like to show in your edge labels.

Next would be to modify the control template for the EdgeControl class (see the sample project for a customization of this - the style that applies to EdgeControl), to have a visualization of the edge labels.  I'm not sure if your requirement is to have the labels visible at all times, or only to have them visible as tooltips when hovering.  Depending on which it is, you may just need to set the tooltip on the path element.  If you want "permanent" labels, you should add a text block and some layout to try to get it in the right place.  Unfortunately, I don't have any recommendations on how to get labels to layout where you want them - that might be something that requires modifications to the layout algorithms to get what you want.  Hopefully others can help you with that.

Oct 6, 2009 at 7:28 AM

OK Thanks, I'll give it a try

Mar 26, 2010 at 11:08 AM
kellyleahy wrote:

The first step would be to define your edge view model class (the one that you need to make part of your BidirectionalGraph-inheriting class) to have a property (and implement INotifyPropertyChanged if necessary) that represents the data you'd like to show in your edge labels.

Next would be to modify the control template for the EdgeControl class (see the sample project for a customization of this - the style that applies to EdgeControl), to have a visualization of the edge labels.  I'm not sure if your requirement is to have the labels visible at all times, or only to have them visible as tooltips when hovering.  Depending on which it is, you may just need to set the tooltip on the path element. 

Hi,

 

would you be so kind and explain your last sentence a bit?

I don't get it. I successfully applied a style to the EdgeControl like this:

 

<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
	xmlns:GraphSharp_Controls="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls">

    <!-- EDGE CONTROL -->
    <Style TargetType="{x:Type GraphSharp_Controls:EdgeControl}">
        <Setter Property="ToolTip" Value="{Binding Path=Edge.ToolTip}" />
    </Style>
</ResourceDictionary>

 

It works fine, if I set some static text in the ToolTips' value. But the Binding to Edge.ToolTip doesn't work. I created an extended Edge-Class like this:

 

  public class MyEdge<T> : Edge<T>
  {
    public MyEdge(T source, T target)
      : base(source, target)
    {

    }

    public override string ToString()
    {
      return ToolTip;
    }

    private string _toolTip;
    public string ToolTip
    {
      get { return _toolTip; }
      set { _toolTip = value; }
    }
  }

It seems, that the EdgeControl doesn't know, how to get to the ToolTip property. It'd be great, if one can provide a little hint for me.

Regards,

Florian

 

 

Apr 1, 2010 at 6:27 PM

It's been a while since I did this, and I don't have time to look into it right now, but did you see any binding errors in the output window when running under the debugger?  Also, when were you setting the ToolTip property - before or after the edge was added to the graph?  If the tooltip was being set after the edge was added to the graph, then you need to properly implement INotifyPropertyChanged in order for the binding to refresh itself.

Kelly

Feb 2, 2011 at 11:30 PM

I have the exact same problem, how to specify the binding in that specific case ?

Feb 8, 2011 at 9:33 PM

Problem solved here: http://graphsharp.codeplex.com/Thread/View.aspx?ThreadId=70832