Selection of a TextBlock inside a LinkPanel

Hello,

I try to implement a Link with three TextBlocks which presents the labels of the link. To edit each of this labels separate I want to make every TextBlock selectable.
I marked every TextBlock selectable via
go:Part.Selectable="True", but it is still not possible to select this TextBlock.
Whats wrong? It is not possible to select a single TextBlock inside a LinkPanel?
Thanks so far,
Thomas

Actually, the Part.Selectable attached property, like most other Part or Node attached properties, is only supposed to be used on the root visual element of the DataTemplate. In this case it governs whether the whole Part (a Link) can be selected.

If you want a particular FrameworkElement in your template to be adorned with the selection, then you need to make sure it has a unique x:Name and that the value of Part.SelectionElementName is that name.

Remember that the Path that is the “LinkShape” should be named “Path”.

So one solution is to implement a mouse event handler that changes the value of SelectionElementName when the user clicks on a named label.

<DataTemplate x:Key="LinkTemplate3">
  <go:LinkPanel go:Part.SelectionElementName="Path" go:Part.SelectionAdorned="True"
                go:Part.Reshapable="True" MouseLeftButtonDown="Link_MouseLeftButtonDown">
    <go:Link.Route>
      <go:Route Routing="AvoidsNodes" Corner="10" RelinkableFrom="True" RelinkableTo="True" />
    </go:Link.Route>
    <Path go:LinkPanel.IsLinkShape="True" x:Name="Path" StrokeThickness="2" Stroke="Black" />
    <TextBlock x:Name="Label1" Text="Above" Foreground="Chocolate" go:LinkPanel.Alignment="0.5 1 0 2" />
    <TextBlock x:Name="Label2" Text="Below" Foreground="Chocolate" go:LinkPanel.Alignment="0.5 0 0 0" />
  </go:LinkPanel>
</DataTemplate>

private void Link_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
  FrameworkElement fe = e.OriginalSource as FrameworkElement;
  Link link = Part.FindAncestor<Link>(sender as UIElement);
  if (fe != null && link != null) {
    // if not the "LinkShape", assume named element is a label
    if (fe.Name != null && fe.Name.Length > 0 && !LinkPanel.GetIsLinkShape(fe)) {
      link.SelectionElementName = fe.Name;
      link.IsSelected = true;
      e.Handled = true;
    } else {
      link.SelectionElementName = "Path";  // default
    }
  }
}

This isn’t complete, of course, but I hope it’s enough to get you started.