Node.ActualWidth is zero (Silverlight)

Hi Walter.

Currently I am implementing export of a Silverlight GoXam diagram to a few output formats (SVG, Visio) for our business needs and I faced the following problem.

When I query Diagram.Nodes and examine their location and appearance (to reproduce these in an output file) sometimes it happens that Node.ActualWidth and Node.ActualHeight are equal to zero.

Here is actions sequense:

  1. the diagram is created and filled with data; all the nodes and links are there and look properly;
  2. the user clicks “Export” btn.;
  3. the diagram.Nodes collection is iterated in order to query nodes appearance properties and export this information.

Here is how I examine nodes:

private SvgElement CreateSvgNode(Node node)
var mainBorder = ((Border)node.VisualElement.FindName(“MainBorder”));

var rect = new SvgRect

Width = border.ActualWidth,
Height = border.ActualHeight,

var svg = new SvgElement();

return svg;

Here is node template I use:

In the bold lines I get ActualWidth and ActualHeight of a node’s inner element and sometimes they both happen to be equal to zero. In these cases ActualWidth and ActualHeight of the node itself and of all node’s child elements are zeros too.

This behaviour occurs mainly with large diagrams containing many nodes with IsSubGraph == true, IsSubgraphExpanded == true. The first idea was that “zero” nodes are just not rendered because of being outside of viewport. But this occurs also if I zoom out the diagram to fit the diagram bounds.

Could you give me some advice about what am I doing wrong and what is the best approach to examine node’s elements actual size in runtime?

GoXam for Silverlight, in order to improve the performance of large diagrams, may remove from the visual tree any Nodes and Links that are completely outside the viewport. Of course GoXam will automatically re-introduce Parts as they become involved with viewport area. But your programmatic examination of Parts that have been removed from the visual tree can see them as having no size.

(On the other hand you say that you still have this problem even after zooming out so that all Parts are visible in the viewport. I can’t explain that unless your code is actually executing before all of those offscreen Parts have been put back into the visual tree.)

Try adding this code to your Diagram’s initialization:
myDiagram.InitialLayoutCompleted += (s, e) => { myDiagram.Panel.Unsupported(23, false); };
This will disable such virtualization and I expect will avoid the problem that you have encountered.

Thank you Walter, I gonna try it.

Hi Walter. Yes, it helped, thanks again.<span =“Apple-tab-span” style=“white-space:pre”>