Links lose routing on resize

Hi there,

I have an application that requires me to load routing (points in a link) from a database, which I can do no problem using :
myDiagram.LayoutCompleted += new EventHandler<DiagramEventArgs>(myDiagram_LayoutCompleted);
So after assigning the routing for each link, the problem occurs when I pan by dragging the diagram around the screen. The links lose all of their routing when they leave the screen and re-enter. Is there some sort of attribute that I am not setting? Panning and zooming on the panel my diagram is in work great, its just when a particular link leave the screen.
Here is is link example link template:
<DataTemplate x:Key="ciruitLinkTemplate">
<go:LinkPanel go:Part.Selectable="False" go:Part.Reshapable="True" go:Part.Movable="True" go:Part.SelectionElementName="Path" >
<go:Link.Route> <go:Route RelinkableFrom="False" RelinkableTo="False" /> </go:Link.Route> <Path go:LinkPanel.IsLinkShape="True" x:Name="Path" Stroke="Black" StrokeThickness="2"> </Path> </go:LinkPanel> </DataTemplate>
Any ideas? I'm pretty stuck.

I don’t know how to reproduce that problem. (Apparently Silverlight, but which version?)

For example, if I run the Dynamic Ports sample and select some nodes along with the links between them, I can reshape some of the links. Then I can drag the selection off-screen. If I scroll to where I dropped the selected nodes and links, the links still have the routing/shape that I gave them.

Note: if the links have Routing=“AvoidsNodes”, the links are supposed to re-route. But according to your LinkTemplate XAML, that’s not the case for you.

I should have mentioned - using silverlight 4.

It happens as soon as the node that the link is connected to leaves the screen. Here is the xaml for a node template.

<DataTemplate x:Key="CloudNodeTemplate" > <Grid go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}" >
<Grid go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}" >


<Image Width=“138” Name=“imgCloud” Source="/NetDoc5.Web.UI;component/images/cloud.PNG" />
<Grid Width=“138”>
<Grid.RowDefinitions>
<RowDefinition Height=“40” />
<RowDefinition Height="" />
<RowDefinition Height=“40” />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=“20” />
<ColumnDefinition Width="
" />
<ColumnDefinition Width=“20” />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column=“1” Grid.Row=“1” FontWeight=“Black” FontSize=“9” HorizontalAlignment=“Center” VerticalAlignment=“Center” Text="{Binding Path=Data.CloudDataBlockData.Name, Mode=TwoWay}" />
<Grid Grid.Column=“1” Grid.Row=“2” Margin=“0,0,9,0”>
<Rectangle Width=“8” Height=“8” Margin=“0,1.5,0,1.5”
go:Node.PortId="{Binding Data.CloudDataBlockData.NetworkID, Mode=TwoWay}" Tag=“Bottom” go:Node.FromSpot=“Center”
go:Node.LinkableTo=“True” go:Node.ToSpot=“Center”
Stroke=“Black”>
<Rectangle.Fill>
<SolidColorBrush Color="#FF00BB00" />
</Rectangle.Fill>
</Rectangle>
<TextBlock FontSize=“6” HorizontalAlignment=“Center” Padding=“0,0,0,0” TextAlignment=“Center”
VerticalAlignment=“Top” Text=“X” Foreground=“Gray” />

</Grid>
</Grid>

</Grid>
</DataTemplate>

First, an unrelated issue: I’m surprised you’re not getting run-time warnings about the data-binding of go:Node.Location on the inner Grid.
go:Node.Location, like most of the Part attached properties, should only go on the root element of the DataTemplate, not on a nested element. (Attached Node properties relating to “ports” are exceptions.)

Second, I modified the Dynamic Ports sample to remove the Diagram.DragSelectingTool: DragSelectingTool="{x:Null}". This allows the user to pan the diagram while still allowing the user to select nodes or links, to move them, and to reshape the links.

I’m still not seeing any problem.

And I’ve tried this in the State Chart sample too, where the link routes are loaded from saved XML. And I tried that two ways: with Route.Adjusting=“Stretch” and with Adjusting=“None”.

I have found the cause of the problem, I’m guessing its a possible bug. it only happens when I use a linkpanel, so for example, this link template works just fine:

<DataTemplate x:Key="cloudLinkTemplate"> <Path go:LinkPanel.IsLinkShape="True" Stroke="Aqua" StrokeDashArray="5" StrokeThickness="2" go:Part.SelectionAdorned="True" go:Part.Reshapable="True"> <go:Link.Route> <go:Route Routing="Normal" Corner="1" RelinkableFrom="True" RelinkableTo="True"/> </go:Link.Route> </Path> </DataTemplate>
----------------------------
...but this one does not
----------------------------
<DataTemplate x:Key="cloudLinkTemplate"> <go:LinkPanel> <TextBlock Text="Hello" /> <Path go:LinkPanel.IsLinkShape="True" Stroke="Aqua" StrokeDashArray="5" StrokeThickness="2" go:Part.SelectionAdorned="True" go:Part.Reshapable="True"> <go:Link.Route> <go:Route Routing="Normal" Corner="1" RelinkableFrom="True" RelinkableTo="True"/> </go:Link.Route> </Path> </go:LinkPanel>

</DataTemplate>

Hmm, that’s still odd, because the State Chart link template uses a LinkPanel.

Yes it is strange, I have three different link templates that I removed from being nested inside linkpanel and all three links are now maintaining their routing now.

Doubly strange: I just copy/pasted your link DataTemplate using a LinkPanel, and could not reproduce any problems. I modified State Chart, and loaded the diagram from XML with modified link routes.

Maybe I am using this wrong - I went into the samples, and modified the template of LinkTemplate in DynamicPorts.xaml to just be contained in the linkpanel like so :

<DataTemplate x:Key="LinkTemplate"> <go:LinkPanel go:Part.SelectionElementName="Path"> <Path go:LinkPanel.IsLinkShape="True" Stroke="Black" x:Name="Path" StrokeThickness="1" go:Part.SelectionAdorned="True" go:Part.Reshapable="True"> <go:Link.Route> <go:Route Routing="Orthogonal" Corner="4" RelinkableFrom="True" RelinkableTo="True"/> </go:Link.Route> </Path> </go:LinkPanel> </DataTemplate>
As a result, all of the routing that initially appears when LinkTemplate isnt contained in the linkpanel dissapear, plus you can no longer select the link. Any idea what I am doing wrong, or is this one of the limitations of a having link content inside a linkpanel?

Well, as I mentioned about most Part attached properties – you need to make sure that they are on the root element of the DataTemplate.

When you wrap the old template contents with a panel, you also need to move those attached properties up to the panel.

<DataTemplate x:Key=“LinkTemplate”>

<go:LinkPanel go:Part.SelectionElementName=“Path”

go:Part.SelectionAdorned=“True” go:Part.Reshapable=“True”>


<Path go:LinkPanel.IsLinkShape=“True” Stroke=“Black” x:Name=“Path” StrokeThickness=“1”>


<go:Link.Route>


<go:Route Routing=“Orthogonal” Corner=“4” RelinkableFrom=“True” RelinkableTo=“True”/>


</go:Link.Route>


</Path>


</go:LinkPanel>


</DataTemplate>

But I wouldn’t have thought that that error would cause the behavior you are seeing.

I just copied the adjustments you gave me to the example, and while the links are now selectable, the routing still doesnt behave like it did initially. Its more or less from A to B in a straight line now, instead of before routes had several points where you could select a link, move it around and adjust it. Now I can select a ‘link’, but I can’t really adjust it or move it around unless I move the node.

Ok… after more messing around once I removed

myDiagram.Panel.Stretch = StretchPolicy.UniformToFill;
The problem went away with the link panel. I'll have to figure out a way to zoom out the encapsulate my entire drawing (they are of various sizes) without using this.

… sorry about all the posts…problem resolved…

I threw :
myDiagram.Panel.Stretch = StretchPolicy.UniformToFill;
at the end of the function in of the LayoutCompleted event and everything is working great now. I had no idea it mattered when you set this property.