About LabelNode in the Link

Can you provide some sample projects about how to use the LabelNode in the Link?

I can't find any in the demo project.
Thanks!

To be clear, are you asking about Nodes that are positioned along link
routes, not just (perhaps complex) FrameworkElements? Only when those
link labels are Nodes can one have Links connect to Links.

If that is the case, I hope it is also clear that you have to use a
GraphLinksModel as your model, because only when there is separate data
for each link can you associate the needed information with each link.

Yes, we ought to add a sample that demonstrates links connecting to links.

First, let’s define the data and the model for a minimal case.
You can use your own data, of course, but for exposition purposes it’s easier to use classes derived from ones that we provide.

[code] var model = new GraphLinksModel<TestNodeData, String, String, TestLinkData>();
model.NodesSource = new ObservableCollection() {
new TestNodeData() { Key=“A” },
new TestNodeData() { Key=“B” },
new TestNodeData() { Key=“C” },

new TestNodeData() { Key="A-B", IsLinkLabel=true }

};
model.LinksSource = new ObservableCollection() {
new TestLinkData() { From=“A”, To=“B”, LabelName=“A-B” },

new TestLinkData() { From="C", To="A-B" }

};
model.LinkLabelNodePath = “LabelName”;
myDiagram.Model = model;[/code]
where the data is defined by:

[code] [Serializable]
public class TestNodeData : GraphLinksModelNodeData { }

[Serializable]
public class TestLinkData : GraphLinksModelLinkData<String, String> {
public String LabelName {
get { return _LabelName; }
set { if (_LabelName != value) { String old = _LabelName; _LabelName = value; RaisePropertyChanged(“LabelName”, old, value); } }
}
private String _LabelName;
}[/code]
Note that GraphLinksModelLinkData does not support link label nodes
out-of-the-box. We have to define a data property to refer from the link
data to the node data that is the label node of the target link –
that’s the LabelName property.

And we have to tell the model how to get that information – by setting
LinkLabelNodePath (or more generally by overriding the
FindLabelNodeKeyForLink method).

In the data, note how we added a TestNodeData that is the label node,
with IsLinkLabel=true, and with its own Key (“A-B”). This could be any
unique string, but I used something that might mean something to a human.

And note how the TestLinkData referred to that label node, by name.

That’s enough to generate a diagram, using the default node and link templates:

So now we can define the appearance by specifying the XAML.

First, note that with the addition of nodes that are link labels, we typically want there to be distinct appearances for regular nodes and for link label nodes. As you can see in the above screenshot, the default link label node template is just a tiny black ellipse.

If you want to use more than one DataTemplate for nodes at the same time, you need to use a DataTemplateDictionary. Here’s the XAML:

[code]
<Window.Resources>
<go:BooleanBrushConverter x:Key=“theBrushChooser”
FalseBrush=“White” TrueBrush=“DodgerBlue” />

<DataTemplate x:Key="NodeTemplate">
  <Border BorderBrush="Black" BorderThickness="1" Padding="4,2,4,2" CornerRadius="3"
          Background="{Binding Path=Node.IsSelected, Converter={StaticResource theBrushChooser}}"
          go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">
    <TextBlock Text="{Binding Path=Data.Key}" MaxWidth="120" TextWrapping="Wrap" />
  </Border>
</DataTemplate>

<DataTemplate x:Key="LinkLabelTemplate">
  <TextBlock Text="{Binding Path=Data.Key}" Background="White"
             go:Node.Selectable="False" go:Node.Avoidable="False" />
</DataTemplate>

<go:DataTemplateDictionary x:Key="NodeTemplates"
                           Default="{StaticResource NodeTemplate}"
                           LinkLabel="{StaticResource LinkLabelTemplate}" />

</Window.Resources>

<go:Diagram x:Name=“myDiagram”
HorizontalContentAlignment=“Center” VerticalContentAlignment=“Center”
NodeTemplateDictionary="{StaticResource NodeTemplates}" />

[/code]
I didn’t bother customizing the appearance of links in this example (i.e., no Diagram.LinkTemplate). The result might be:

I moved the nodes around; the “C” node is selected.

We could improve the support for link label nodes by automating some more operations that are common. In particular, I believe that if you want to have each user-drawn link have a link label node, you need to override PartManager.OnLinkAdded to add such a node data and associate it with the link data. In the future we could add a property to do that automatically.

There are probably other operations we could make easier to use too.