I have done some changes in your code and after changes it has stopped working. I must be doing some mistake and need your help to find it.
<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
1. To reproduce Issue:
a. Execute the application
b. Click on the Issue button
2. To check correct behavior:
a. Execute the application
b. Click on Correct button
The reason for using buttons for adding nodes: Actual data will come via WCF services asynchronous based on other selection of other controls on page.
public partial class test : UserControl
{
public test()
{
InitializeComponent();
try
{
var model = new GraphLinksModel<MyNode, String, String, MyLink>();
model.Modifiable = true;
myDiagram.Model = model;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CollapseExpandButton_Click(object sender, RoutedEventArgs e)
{
}
private void btnIssue_Click(object sender, RoutedEventArgs e)
{
HideButtons();
var model = myDiagram.Model;
myDiagram.StartTransaction("AddNode");
MyNode mainNode = new MyNode("A", "1");
model.AddNode(mainNode);
myDiagram.CommitTransaction("AddNode");
}
private void btnCorrect_Click(object sender, RoutedEventArgs e)
{
HideButtons();
var model = myDiagram.Model;
myDiagram.StartTransaction("AddNode");
MyNode mainNode = new MyNode("A", "1");
model.AddNode(mainNode);
MyNode nodeB = new MyNode("B", "2");
model.AddNode(nodeB);
model.AddLink(mainNode, null, nodeB, null);
myDiagram.CommitTransaction("AddNode");
}
private void HideButtons()
{
btnCorrect.Visibility = Visibility.Collapsed;
btnIssue.Visibility = Visibility.Collapsed;
}
}
public class MyNode : GraphLinksModelNodeData<String>
{
public MyNode()
{
this.MyNodeText = "";
this.ShowButton = Visibility.Visible;
}
public MyNode(String text, String key)
{
this.Key = key;
this.MyNodeText = text;
this.ShowButton = Visibility.Visible;
}
public String MyNodeText { get; set; }
public Visibility ShowButton { get; set; }
}
public class MyLink : GraphLinksModelLinkData<String, String>
{
public String LabelText
{
get
{
return "Is-A";
}
}
}
.XAML:
<UserControl x:Class="TermGraphViewer.test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:go="clr-namespace:Northwoods.GoXam;assembly=Northwoods.GoSilverlight"
xmlns:golayout="clr-namespace:Northwoods.GoXam.Layout;assembly=Northwoods.GoSilverlight"
Height="700">
<UserControl.Resources>
<DataTemplate x:Key="NodeTemplate">
<StackPanel Orientation="Vertical" go:Part.SelectionAdorned="True"
go:Node.IsTreeExpanded="True">
<Button Visibility="{Binding Path=Data.ShowButton}" x:Name="myCollapseExpandButton"
Click="CollapseExpandButton_Click" FontSize="8" VerticalAlignment="Top"
Content="+" Width="15" Height="15" />
<go:NodePanel Sizing="Auto">
<Path go:NodePanel.Figure="Rectangle" Fill="LightGray" />
<TextBlock Text="{Binding Path=Data.MyNodeText}" MinWidth="100" MaxWidth="100"
TextWrapping="Wrap" ToolTipService.ToolTip="{Binding Path=Data.MyNodeText }" />
</go:NodePanel>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="LinkTemplate">
<go:LinkPanel go:Part.SelectionElementName="Path" go:Part.SelectionAdorned="False">
<go:Link.Route>
<go:Route RelinkableFrom="False" RelinkableTo="False" />
</go:Link.Route>
<Path go:LinkPanel.IsLinkShape="True" x:Name="Path" Stroke="Black" 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="Along" />
<TextBlock Text="{Binding Path=Data.LabelText, Mode=TwoWay}" go:LinkPanel.Offset="8 8"
FontSize="9" go:Part.TextEditable="False" go:LinkPanel.Orientation="Upright" />
</go:LinkPanel>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" VerticalAlignment="Stretch">
<StackPanel Orientation="Vertical" >
<StackPanel Orientation="Horizontal">
<Button x:Name="btnCorrect" Content="Correct" Click="btnCorrect_Click"></Button>
<Button x:Name="btnIssue" Content="Issue" Click="btnIssue_Click"></Button>
</StackPanel>
<StackPanel VerticalAlignment="Stretch" Height="600" >
<go:Diagram Grid.Row="1" x:Name="myDiagram" Height="600"
Padding="10"
NodeTemplate="{StaticResource NodeTemplate}"
LinkTemplate="{StaticResource LinkTemplate}">
<go:Diagram.Layout>
<golayout:LayeredDigraphLayout LayerSpacing="150" />
</go:Diagram.Layout>
</go:Diagram>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>