go:Part.SelectionAdorned="True" MouseRightButtonDown="MyDiagram_MouseRightButtonDown"
MouseRightButtonUp="MyDiagram_MouseRightButtonUp"
Width="827" InitialScale="0.75"
It’s commonplace to data-bind the Node.Location property to the Location property of your data:
go:Node.Location="{Binding Path=Data.Location}"
Many of the sample demonstrate this.
If you want the data to automatically get updated Location values as the user or the diagram layout moves nodes, make the Binding Mode=TwoWay.
Are you sure that you want the NodeData.Name property to be the unique key?
If so how are you using the NodeData.Key property?
Walter,
Remember that GoDiagram does not use models and data-binding, so perhaps that’s a new concept for you in GoXam.
The default Diagram.Layout and all of the standard layouts try to make sure each Node has a defined Location value.
So you don’t need to specify it.
You don’t need a data-binding for Node.Location if you don’t need to get the location point from the data.
You told the model that the “Name” property is the unique identifier.
You told the TextBlock that it’s Text property gets its value from the “Name” property of the data.
Because the model tries to make sure the “Name” property is unique, it increments it until it is unique.
The TextBlock then shows that value.
Thanks Walter
The Key/Name issue now resolved model.NodeKeyPath = "Key"; changed from "Name". I have added go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}" to the NodeTemplate as I need to get the bottom right corner location of the right clicked node so that I can place a temporary node at that point with additional information. Code still placing nodes as per the image.Yes; in fact the default value for model.NodeKeyPath is “Key”, when the data class is or inherits from one of our predefined node data classes.
I think I misunderstood your intent.
The Diagram.Layout, which is a TreeLayout in your case, is causing everything to be laid out again every time you add or remove a Node or a Link.
I’m not sure when you want the diagram layout to happen automatically.
You can control when it happens by setting the TreeLayout.Conditions property.
If you don’t want it to happen when nodes or links are added or removed, try setting Conditions=“None” or to “InitialOnly”, depending on whether you always want to call Diagram.LayoutDiagram() explicitly when you need it or only automatically when it would want to do an initial layout.
To remove everything from the diagram you can:
Walter,
Node n = null;
n = Part.FindAncestor<Node>(elt);
NodeData pd = (NodeData) n.Data;
_clickedNode = new ClickedNode { LocationX = pd.Location.X, LocationY = pd.Location.Y, Height = n.ActualHeight, Width = n.ActualWidth };
MyDiagram.Model.AddNode(pdNode);
MyDiagram.CommitTransaction(“Node”);
MyDiagram.LayoutDiagram();
What you are forgetting is what I suggested originally: the data-binding of go:Node.Location="{Binding Path=Data.Location}".
Using data-binding, perhaps with a converter, is the most natural way of effecting change by modifying a data property.
Otherwise you have to write some code to call Diagram.PartManager.FindNodeForData to set the properties, such as Node.Location in this case.
I have the binding to location in the data template, inside the Border tag, and it’s still failing. Is this the correct place to put it ?
Yes, that’s right. You’ll see many of the samples do the same thing, and some of those samples also modify node data to position the Node.
Working