获取相对于可滚动网格的鼠标位置

发布于 2024-10-02 21:45:40 字数 410 浏览 0 评论 0原文

因此,我的网格此时动态扩展至任意高度,我可以向下滚动以使用相对于网格的 e.GetPosition(mainGrid) 获取坐标。直到我滚动时它都工作正常。我举个例子。

我有一个网格,背景中有一些图像。此时网格的高度为 950。如果我将选择方块拖动到网格的最底部并获取相对于它的位置(e.GetPosition(mainGrid)),我将得到 950。太棒了。

现在,当我调整大小超过 950(假设为 1200)时,我必须向下滚动才能看到网格的其余部分。我做了同样的事情,在网格底部绘制一个选择方块,期望我的 Y 坐标为 1200,但总是得到 950 的 Y 坐标。换句话说,我滚动到的偏移量没有被应用到 Y 坐标,我不确定如何指示这一点。我非常想对 WPF 说“获取相对于网格的位置,但确保始终从网格左上角 0,0 处的原点获取它,而不仅仅是从网格可见的部分获取它”你”。

So my grid at this point dynamically expands to whatever height and I can scroll down to get coordinates using e.GetPosition(mainGrid) relative to the grid. It works fine up until when I scroll. I'll give an example.

I have a grid with some image in the background. The grid's height at this point is 950. If I drag my selection square at the very bottom of the grid and get the position relative to it (e.GetPosition(mainGrid)), I get 950. Great.

Now, when I resize past 950, to let's say 1200, I have to scroll down to see the rest of my grid. I do the same thing, draw a selection square at the bottom of my grid expecting my Y-coordinate to be 1200 but instead always get a Y-coordinate of 950. In other words, the offset of which I scrolled to is not being applied to the Y-coordinate and I am unsure of how to do indicate this. I pretty much want to say to WPF "Get the position relative to the grid but make sure that you get it always from the origin at the upper-left of grid at 0,0 and not just the portion of the grid that is visible to you".

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

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

发布评论

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

评论(1

不语却知心 2024-10-09 21:45:40

固定的。我有一个外部网格作为我的容器和一个内部网格。我的目标是外部网格,认为当内部网格改变大小时它的大小也会改变,但我想不会。现在通过瞄准内部网格来工作。

Fixed. I have an outer grid acting as my container and an inner grid. I was targeting the outer grid thinking it would change in size too when the inner grid changed size but I guess not. Works now by targeting the inner grid.

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