0

I have a XAML based ScatterView to which I'm programmatically adding more Scatterviews (henceforth known as Scatter2s).

Each of the Scatter2s work fine - they each contain ScatterViewItems which in turn contain an Ellipse shape, and these are all drawn to the Surface perfectly as wanted.

In trying to draw lines between two ellipses, I attempt to get the Scatter2.[AScatterViewItem].Center.X and .Y properties, so I can set the X1Y1,X2Y2 properties of the line, but they return as NaN. I've also tried ActualCenter which results in the same outcome.

I initially thought it was because I was trying to access these properties before the ellipses were drawn on screen, but I printed the property values after they've been drawn and same result.

I checked to ensure that each of the ScatterViewItems width and height are explicitly set before drawing, as are the ellipse width and height - just in case that would throw the calculation of a center property off.

Is there a better way to get the position of a ScatterViewItem which has not been explicitly positioned than using the Center property?

Thanks


In Node:

public void CenterToString()
{
    Console.Out.WriteLine("Actual centre: " + svi.ActualCenter.toString());
    Console.Out.WriteLine("Centre: " + svi.Center.toString());
}

In my main class

Node node_one = ((GeneNetwork) context).getNode(localNodeIds[0]);
node_one.CenterToString();

gives output:

Actual centre to string: NaN,NaN
Centre to string: NaN,NaN

The code which adds a Node to the main ScatterView (context.Items.Add(svi)) is called before the CenterToString() function.

Could it have anything to do with where I'm placing this in my SurfaceWindow class? Currently, everything is in onInitialised(), after the call to base.OnInitialised.

ataulm
  • 15,195
  • 7
  • 50
  • 92
  • note, it does return a value if I initialise the Center property with a valid Point object, but I want the Surface to place the items itself. – ataulm Nov 19 '11 at 11:21

1 Answers1

0

Center is not set until you set it or user moves the SVI. I would just set it since the SV just places them randomly otherwise. If you really don't want that you will need to use TransformToAncestor as in Get Absolute Position of element within the window in wpf to get the position of the center of the SVI relative to its parent SV.

Community
  • 1
  • 1
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • Thanks xyzzer, I'll try that and report back. I imagine I'll be setting it eventually - but need it as-is for a demo. – ataulm Nov 19 '11 at 18:41
  • Is there a way to see a tree view of the layouts used similar to Android's Hierarchy Viewer? The elements I've added are added programmatically, except for the initial ScatterView. Using TransformToAncestor says not an ancestor (same with descendent), and TransformToVisual says doesn't share an ancestor. – ataulm Nov 20 '11 at 12:23
  • Thanks xyzzer, superb tool. It also confirms that the visual is a descendent of the supplied root for TransformToAncestor, so I can't see why it's saying it's not. – ataulm Nov 20 '11 at 20:01
  • marked this as the answer as it's what needs to be done - the reason it's not yet working in my case is because the visual tree is still being assembled at the time I'm trying to use the TransformToAncestor (http://goo.gl/OJK2O) – ataulm Nov 20 '11 at 20:10