Link label visibility problems

I’m trying to toggle the visibility of link labels, but it just is not working. I’m using GoXam 1.2.2 for Silverlight and am doing the following:

  • Toggle visibility off at the diagram level.
  • Draw a link (link model gets created with IsLabelVisible= false)
  • Toggle visibility on (this sets IsLabelVisible to true for all objects in the LinksSource collection, inside of a transaction of course)
  • Link label is still not visible.
  • Move one of the nodes attached to the link and the label pops into view.

Here’s my link template, with the offending Border highlighted in red:

[code]<DataTemplate x:Key="linkTemplate">
  <go:LinkPanel DataContext="{Binding Data}"
    go:Part.SelectionElementName="Path"
    go:Part.SelectionAdorned="True"
    go:Part.Selectable="True"
    go:Part.LayerName="Background"
    Opacity="{Binding Opacity}"
    go:Part.Reshapable="True">
    <go:Link.Route>
      <go:Route Routing="{Binding Data.Routing}"
        Curve="{Binding Data.Curve}"
        Corner="10" />
    </go:Link.Route>
    <go:LinkShape go:LinkPanel.IsLinkShape="True"
      StrokeThickness="10"
      Stroke="Transparent" />
    <go:LinkShape StrokeDashArray="{Binding FormatSettings.LineStyle}"
      go:LinkPanel.IsLinkShape="True"
      x:Name="Path"
      StrokeThickness="{Binding FormatSettings.LineThickness}"
      Stroke="{Binding FormatSettings.LineBrush}" />
    <Polyline StrokeThickness="{Binding FormatSettings.LineThickness}"
      Points="8 4 0 8 2 4 0 0"
      go:LinkPanel.Index="-1"
      go:LinkPanel.Alignment="Center"
      go:LinkPanel.Orientation="Along"
      Visibility="{Binding Direction, ConverterParameter=From, Converter={StaticResource arrowheadToVisibilityConverter}}"
      Fill="{Binding FormatSettings.LineBrush}" />
    <Polyline StrokeThickness="{Binding FormatSettings.LineThickness}"
      Points="0 4 8 0 6 4 8 8"
      go:LinkPanel.Alignment="Center"
      go:LinkPanel.Index="0"
      go:LinkPanel.Orientation="Along"
      Visibility="{Binding Direction, ConverterParameter=To, Converter={StaticResource arrowheadToVisibilityConverter}}"
      Fill="{Binding FormatSettings.LineBrush}" />
    <Border go:LinkPanel.Orientation="None"
      Background="White"
      CornerRadius="3"
      BorderThickness="1"
      BorderBrush="Gray"
      Visibility="{Binding IsLabelVisible, Converter={StaticResource BoolToVisibilityConverter}}">
      <Border.Effect>
        <DropShadowEffect BlurRadius="5"
          Direction="-45"
          Opacity="0.5"
          ShadowDepth="3"
          Color="Gray" />
      </Border.Effect>
      <Grid>
        <Border Visibility="{Binding Name, Converter={StaticResource stringToVisibilityConverter}}"
          Background="{Binding FormatSettings.LabelBackground}">
          <TextBlock go:Part.TextEditable="True"
            Text="{Binding Name, Mode=TwoWay}"
            TextWrapping="Wrap"
            TextAlignment="Center"
            Margin="5"
            Foreground="{Binding FormatSettings.LabelForeground}"
            FontSize="{Binding FormatSettings.LabelFontSize}"
            FontWeight="{Binding FormatSettings.IsLabelBold, Converter={StaticResource boolToFontWeightConverter}}"
            FontStyle="{Binding FormatSettings.IsLabelItalics, Converter={StaticResource boolToFontStyleConverter}}"
            TextDecorations="{Binding FormatSettings.IsLabelUnderline, Converter={StaticResource boolToTextDecorationConverter}}" />
        </Border>
        <Border Visibility="{Binding Name, ConverterParameter=invert, Converter={StaticResource stringToVisibilityConverter}}">
          <TextBlock go:Part.TextEditable="True"
            Style="{StaticResource NoInfoTextBlock}"
            Margin="5"
            Text="{Binding NoInfoName, Mode=TwoWay}" />
        </Border>
      </Grid>
    </Border>
  </go:LinkPanel>
</DataTemplate>[/code]

You may need to call Remeasure() on each modified Link.

By the way, I do recommend upgrading to version 1.2.6, which fixes a number of bugs, although it will not affect the behavior here.

That worked, but I’m puzzled as to why its necessary. Normally I’d expect data binding to “just work”. And I don’t see any calls to Link.Remeasure() in the LinkDemo sample.

Noted on the version upgrade, I’ll look into it.

I’m still unclear as to when one should call Part.Remeasure. I just found an issue where the diagram thought my nodes were the wrong size. The primary visual component is a custom control which can change size based on some of its data. Detecting when this condition occurs and calling Part.Remeasure() on that node fixes the problem.

Do Parts (and thus Nodes and Links) not detect when their content changes size?

Nodes do establish a SizeChanged event handler on their content. But I think that isn’t the problem for you – it’s that your custom control isn’t being measured and arranged again.

I can’t explain why that isn’t working for you – I hadn’t ever heard of any such problems for Nodes. Are you sure that those data changes are invalidating the measure of the respective elements?

I’m not sure if the custom control is invalidating the measure correctly, but I’ll definitely look into it. Thanks!