ScatterViewItem.Center(X 和 Y)属性返回 NaN

发布于 2024-12-17 08:29:00 字数 1348 浏览 4 评论 0原文

我有一个基于 XAML 的 ScatterView,我以编程方式向其中添加更多 Scatterview(以下称为 Scatter2s)。

每个 Scatter2s 都工作正常 - 它们每个都包含 ScatterViewItem,而这些 ScatterViewItem 又包含一个 Ellipse 形状,并且这些都完美地绘制到 Surface如所愿。

在尝试在两个椭圆之间绘制线条时,我尝试获取 Scatter2.[AScatterViewItem].Center.X.Y 属性,以便我可以设置 X1Y1,X2Y2该行的属性,但它们返回为 NaN。我也尝试过 ActualCenter ,结果相同。

我最初认为这是因为我试图在屏幕上绘制省略号之前访问这些属性,但我在绘制属性值后打印了它们并得到了相同的结果。

我检查以确保在绘制之前显式设置每个 ScatterViewItem 的宽度和高度,就像椭圆的宽度和高度一样 - 以防万一会导致中心属性的计算失败。

有没有比使用 Center 属性更好的方法来获取尚未显式定位的 ScatterViewItem 的位置?

感谢


节点:

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

在我的主类中

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

给出输出:

字符串的实际中心:NaN,NaN
中心到字符串:NaN,NaN

调用将 Node 添加到主 ScatterView (context.Items.Add(svi)) 的代码在 CenterToString() 函数之前。

它与我将其放置在 SurfaceWindow 类中的位置有什么关系吗?目前,一切都在调用 base.OnInitialized 之后的 onInitialized() 中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗梦空间 2024-12-24 08:29:00

在您设置中心或用户移动 SVI 之前,不会设置中心。我只会设置它,因为 SV 只是随机放置它们,否则。如果您确实不想这样做,则需要使用 TransformToAncestor,如 获取wpf中窗口内元素的绝对位置以获取SVI的中心相对于其父SV的位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文