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"<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>
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);
}
}
}
}