New node


I am creating a node as described below. What I want is to put the just created node in a special layer (a custom layer called FrameLayer). As you can see I use FindNodeForData after AddNode, all is fine so far but this does not work because I think that the new node adding is not done when I set the layer. The code below puts the new node back to default layer. If I set it back to FrameLayer at LayoutComplete event all is fine. How could I do this without using the LayoutComplete event?
Dim node As New GateData
node.GateType = "FrameA3"
node.Page = "Ny ram"
node.IsSelectable = False
node.Location = new Point(100,100)
Dim newnode As Node = myDiagram.PartManager.FindNodeForData(node, myDiagram.Model)
newnode.LayerName = "FrameLayer"
Thank you

I’m unable to reproduce any problem with Part.LayerName.

When are you executing this code? Are you sure that the NodeLayer with Id = “FrameLayer” actually exists and is a child of the Diagram.Panel?

On a separate but related issue, it’s commonplace to data-bind the go:Part.LayerName to a data property naming the layer. So one would set that property on the data before adding the data to the model’s collection of node data. Or, if that property raised the PropertyChanged event in the setter, you could set that property at any time in order to change the Layer that the Node is in.

I’m just sugggesting that you don’t need to call PartManager.FindNodeForData in order to change the Part.LayerName. But I could see you wanting to do so anyway if this were a special case or if you couldn’t modify the data class appropriately.

This code is executed at any time when the user wants to add such node, long after the Layer is added to the model (wich it is in the template loaded event).

When debugging my code I can see that the layer is set correctly directly at the command but then after a few other actions in the code I can see that it steps back into the gatedata class for initiating the just added node. And somewhere here the layer get set back to default. (There are quit alot of bindings in this node btw).
I got your point about binding the layer and will do so, but I am still confused about the other issue...
Thank you

When the Node is created, it is first added to a temporary layer so that the node’s visual tree can be elaborated and data-bindings performed. Then the PartManager moves the node to its Part.LayerName layer (if it’s a different layer).

So a node will temporarily be in other layers before getting into the right one. Unfortunately the data-bindings aren’t going to be evaluated correctly unless it’s in the visual tree.

I don’t know if this further explanation helps any or not, but I hope it helps.