Custom Layers

Hi Walter

I’d like to ask some questions regarding the use of custom layers. I’ve also noticed a behaviour which I’m not sure is a bug or not.

The first question is what is the proper way to instantiate and use custom layers?
Currently I’m doing the following:

var nodeLayer = new NodeLayer();
nodeLayer.Id = Guid.NewGuid().ToString();
diagram.Panel.Children.Add(nodeLayer);

Is this the correct way of doing it?

Secondly, do custom layers enroll in transactions? For example, If I add a custom layer during a transaction and then rollback the transaction, is the custom layer automatically removed? Are property changes of a custom layer tracked by a transaction?

Lastly, I noticed an odd behaviour regarding custom layers.
This is the current process:

  1. Create custom link and node layers and add them to the diagram
  2. Create nodes and links
  3. Add nodes and links to a group
  4. Bind the group, nodes and links to the custom layers using the Part.LayerName dependency property

The first time I perform this process it works as expected. However, If I repeat the process a second time, the links do not plot properly. See the image below: (the group on left is when I execute the process the first time. The group on the right is when I execute the process the second time)

Thanks
Justin

No, the insertion or removal or modification of Layers do not have any changes recorded in the UndoManager. In fact the same is true for changes to the Diagram itself or to all of the FrameworkElements that constitute your Nodes and Links. It’s just changes to the Model that get recorded in the UndoManager.

Regarding the second problem, you might want to try the DLL that I just sent you before I read this forum post. I have no idea if that will help or not, but it wouldn’t hurt to try, since I believe it does address these problems with Silverlight that you have pointed out before.

Hi Walter

Thanks for the explanation.

I tested the latest DLL you sent and unfortunately it does not fix the issue above.

OK, we’ll have to look into it.
I hope the other cases are now being handled satisfactorily.

I have another question: If you add a custom node layer, is it then to compulsory to add a corresponding custom link layer?

No, you can do whatever your application needs.
The predefined “Background” and “Foreground” layers are just there for convenience.

Hi Walter

Thanks. I’ll re-check those cases with the new DLL hopefully tomorrow

Here’s what I noticed.
In my code I was doing some similar to the following:

var nodeLayer = new NodeLayer();
nodeLayer.Id = Guid.NewGuid().ToString();
var linkLayer = new LinkLayer();
linkLayer.Id = Guid.NewGuid().ToString();

diagram.Panel.Children.Add(nodeLayer);
diagram.Panel.Children.Add(linkLayer);

node.LayerID = nodeLayer.Id;
link.LayerID = linkLayer.Id;

This would produce the issue described in the first post. However, If I changed the code in bold to following:

node.LayerID = nodeLayer.Id;
link.LayerID = nodeLayer.Id;


Thereby making nodes and links use the same NodeLayer, then the issue would resolve itself. However, I’m not sure if this is a hack or fortunate coincidence. Can you please advise?

Thanks

What actually happens in that case is that when adding a Link it searches for the Layer with the node layer’s GUID. It won’t find it, because it only searches LinkLayers – it cannot consider any NodeLayers. That results in the Link being added to the default LinkLayer.

Thanks for the explanation. I’ll investigate further as to why my custom LinkLayer is misbehaving.

Oh, no, I doubt that it is your problem. It has to do with how Silverlight loses some internal state when an element is removed from the visual tree or when it is not visible, and with what happens with how GoXam measures objects when they are not visible. Unfortunately it is quite different from WPF, which handles these unusual cases much more reasonably, from our point of view.

[quote]Oh, no, I doubt that it is your problem. It has to do with how Silverlight loses some internal state when an element is removed from the visual tree or when it is not visible, and with what happens with how GoXam measures objects when they are not visible. Unfortunately it is quite different from WPF, which handles these unusual cases much more reasonably, from our point of view.[/quote]

Sorry to revive an old thread but I’m trying to think of a robust way to deal with the issue where Silverlight or GoXam has problems measuring items that aren’t visible yet.

My initial plan was to use delays between transactions in the hope that the layout system had enough time to do what it needed to do before I started doing any UI manipulation.

For example, something similar to this pseudo-code:

<span ="Apple-tab-span" style="white-space:pre">	</span>Dispatcher.BeginInvoke(() =>{
<span ="Apple-tab-span" style="white-space:pre">		</span>//Create diagram modes
<span ="Apple-tab-span" style="white-space:pre">	</span>});

<span ="Apple-tab-span" style="white-space:pre">	</span><b>Delay X milliseconds using a timer/task</b>

<span ="Apple-tab-span" style="white-space:pre">	</span>Dispatcher.BeginInvoke(() =>{
<span ="Apple-tab-span" style="white-space:pre">		</span>//Center a diagram part
<span ="Apple-tab-span" style="white-space:pre">		</span>Diagram.Panel.CenterPart(part);
<span ="Apple-tab-span" style="white-space:pre">	</span>});

However, regardless of how long I make the delay the results are always unreliable.
Can you suggest a way that I might be able to deal with this issue?

Thank