Updating link label text not displayed properly

I am trying to update the link label text programatically. But it is not displayed properly when the new link text is bigger than old text.

This is initial link text where link text = "test"
It shows following incorrect text when I programatically update the link text. (link text="Updated Link Text")
I expect it should display as below. (It corrects isself when I click on link)
I think that the textbloxk which hold the text is not getting resized when we provide new text for it. Is there any way I can force it to update itself and displays the new label text properly?
Could you please check my code if I am doing any mistake?
------
MainPage.XAML

<UserControl x:Class="LinkTextIssue.MainPage"<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable="d"

xmlns:go="clr-namespace:Northwoods.GoXam;assembly=Northwoods.GoSilverlight"

xmlns:gotool="clr-namespace:Northwoods.GoXam.Tool;assembly=Northwoods.GoSilverlight"

xmlns:golayout="clr-namespace:Northwoods.GoXam.Layout;assembly=Northwoods.GoSilverlight"

d:DesignHeight="300" d:DesignWidth="400">

<UserControl.Resources>

<DataTemplate x:Key="NodeTemplate">

<StackPanel Orientation="Vertical" go:Part.SelectionAdorned="True" go:Part.Deletable="False"

go:Node.IsTreeExpanded="True" >

<go:NodePanel Sizing="Auto"

go:Node.LinkableFrom="False"

go:Node.LinkableTo="False"

>

<Path go:NodePanel.Figure="Rectangle" Fill="LightGray" />

<StackPanel>

<TextBlock Text="{Binding Path=Data.Name}"

MinWidth="100" MaxWidth="100" TextWrapping="Wrap"

HorizontalAlignment="Left" />

</StackPanel>

</go:NodePanel>

</StackPanel>

</DataTemplate>

<DataTemplate x:Key="LinkTemplate">

<go:LinkPanel go:Part.SelectionElementName="Path" go:Part.SelectionAdorned="True" >

<go:Link.Route>

<go:Route RelinkableFrom="False" RelinkableTo="False" />

</go:Link.Route>

<Path go:LinkPanel.IsLinkShape="True" Stroke="Black"

x:Name="Path" StrokeThickness="1" />

<Polyline Stroke="Black" StrokeThickness="1"

Points="0 0 8 4 0 8" go:LinkPanel.Alignment="1 0.5"

go:LinkPanel.Index="-1" go:LinkPanel.Orientation="Upright" />

<TextBlock Text="{Binding Path=Data.LabelText, Mode=TwoWay}" go:LinkPanel.Offset="8 8"

FontSize="9" go:Part.TextEditable="False" go:LinkPanel.Orientation="Along" />

</go:LinkPanel>

</DataTemplate>

</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="White">

<Grid.RowDefinitions>

<RowDefinition Height="35"/>

<RowDefinition Height="*"/>

</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" Grid.Row="0">

<Button Content="Reset" x:Name="btnReset" Click="btnReset_Click"></Button>

<Button Content="Change Link Text" x:Name="btnChangeLinkText" Click="btnChangeLinkText_Click"></Button>

</StackPanel>

<go:Diagram x:Name="graph1" Grid.Row="1"

HorizontalContentAlignment="Stretch"

VerticalContentAlignment="Stretch"

Padding="10"

NodeTemplate="{StaticResource NodeTemplate}"

LinkTemplate="{StaticResource LinkTemplate}">

<go:Diagram.Layout>

<golayout:LayeredDigraphLayout LayerSpacing="150" x:Name="graphLayout" >

</golayout:LayeredDigraphLayout>

</go:Diagram.Layout>

</go:Diagram>

</Grid>

</UserControl>

MainPage.XAML.CS

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using Northwoods.GoXam.Model;

using System.ComponentModel;

namespace LinkTextIssue

{

public partial class MainPage : UserControl

{

MyLink link;

public MainPage()

{

InitializeComponent();

Init();

}

private void Init()

{

var model = new GraphLinksModel<MyNode, String, String, MyLink>();

model.Modifiable = true;

model.NodeKeyPath = "Name";

MyNode node1 = new MyNode("node1");

MyNode node2 = new MyNode("node2");

model.AddNode(node1);

model.AddNode(node2);

link = model.AddLink(node1, "", node2, "");

link.LabelText = "test";

graph1.Model = model;

}

private void btnReset_Click(object sender, RoutedEventArgs e)

{

graph1.LinksSource = null;

graph1.NodesSource = null;

Init();

}

private void btnChangeLinkText_Click(object sender, RoutedEventArgs e)

{

if (link != null)

{

link.LabelText = "Updated Link Text";

}

}

}

public class MyNode : GraphLinksModelNodeData<String>

{

public string Name { get; set; }

public MyNode(string name)

{

Name = name;

Key = name;

}

}

public class MyLink : GraphLinksModelLinkData<String, String>

{

String labelText;

public String LabelText

{

get

{

return labelText;

}

set

{

string oldVal = labelText;

labelText = value;

RaisePropertyChanged("LabelText", oldVal, value);

}

}

}

}

Whenever one changes a model or any model data, one must do so inside a transaction.

Hi Walter,

I tried using transaction but it is not redrawing the link text.
Is is correct?

private void btnChangeLinkText_Click(object sender, RoutedEventArgs e)<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

{

var model = graph1.Model;

model.StartTransaction("AddLink");

if (link != null)

{

link.LabelText = "Updated Link Text";

}

model.CommitTransaction("AddLink");

}

Thanks,
Hardik

Yes, that’s better.
(Although I should point out an unrelated problem, in that your “LabelText” property setter is calling RaisePropertyChanged unconditionally, instead of checking first that the value really did change.)

I would need to investigate further why the link label isn’t updating properly.
For now perhaps the following will work inside your transaction:
graph1.PartManager.FindLinkForData(link, model).Remeasure();

Hi Walter,

Your suggestion of using Remeasure() has solved my problem.
I will also implement your other suggestion about conditionally using RaisePropertyChanged.
Thanks a lot,
Hardik

Hi Walter,
I’ve run into the same problem that the label of the link is not updated.
In my case it’s not really change to the diagram model because we simply allow the user to change data that is related to the diagram, but it’s not the diagram itself. Specifically we display a process and each link represent single activity. When the user change the type of the activity we would like to reflect the updated activity type in the diagram, but it’s not change to the diagram like different from or to nodes.

I’ve used your Remeasure workaround - I hope it will not cause performance problem or other side effects - currently it look like it working great.

Ido.