Node LayerName is not consistent with Layer ref

I’ve found yet another edge-case in GoWPF.
As you might remember I have 20 layers in order to control the ZOrder of my containers.
I’ve add a string property called LayerID on my NodeViewModel.
I’ve also bound the LayerName property to my LayerID.

This works fine when I open my diagram window and then add content into my model.

The problem appear when I add data to the model during the window Load event.
Eventually I’m getting to situation where I can see in the debugger that a container node’s property of LayerName is Containers0 (I’ve put Container0 at the back, Containers1 in front of it, Container2 in front of it and so forth) but the Layer.Id property return empty string which maps to the default layer.

I’ll try to create a repro project because I understand that only getting to this state without repro it is half the work.

Thank you.

When do you create the additional Layers? I’m guessing that because so much stuff is happening asynchronously, perhaps some of the layers don’t exist yet when loading some of the node/group data, so they end up in the default layer.

Another way to check this: make sure all of the Layers exist before you assign your model to the diagram.

Thanks for the blazing fast answer :)
A workaround of delay the addition to the model really solve the problem so I think you right and it is the order in which things happen.

Thank you,

OK, The order was really the source of the problem.
The cause is that I’m adding data to the model in the UserControl.Loaded event but I only add the layers in the Diagram.Loaded event which comes after the UserControl.Loaded event.
I’ve solve it buy adding the layers to the diagram inside the Diagram.TemplateApplied event.

After reading this article I understand that it is by design that Loaded event is raise on the root element (UserControl) first and only later on its children.