获取相对于可滚动网格的鼠标位置
因此,我的网格此时动态扩展至任意高度,我可以向下滚动以使用相对于网格的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
固定的。我有一个外部网格作为我的容器和一个内部网格。我的目标是外部网格,认为当内部网格改变大小时它的大小也会改变,但我想不会。现在通过瞄准内部网格来工作。
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.