在 WPF 中测试几何体时出现问题
我的 WPF 应用程序有一个画布,我可以在其中绘制表格和连接它们的线条。当用户单击表格或行时,我捕获该控件的 MouseDown 事件并在后台执行各种操作。问题是,虽然表格很大,所以不会出现任何问题,但线条只有几个像素粗,所以点击它很困难而且烦人 因为你需要精确的精度。
我的问题是:有没有办法给几何图形一些不可见但仍然捕获点击的“边距”? (或者任何其他适合我想要实现的目标的解决方案,也许有更好的方法,比如在画布上进行命中测试?)。
提前致谢!!
My WPF application has a canvas on which I draw tables and lines that connect them. When a user clicks on a table or line, I capture the MouseDown event of that control and do various stuff in the background. The problem is that while the tables are big, and so present no problems, the lines are only a couple of pixels thick, so clicking it's difficult and annoying
because you need pinpoint precision.
My question is: is there a way to give a Geometry a bit of "margin" that is invisible but still captures clicks? (or any other solution that would work for what I'm trying to achieve, maybe there's a better approach, like hit-testing on the canvas maybe??).
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 WPF 中,您可以使用透明颜色进行绘制(0 表示 Alpha 通道)。如果您在正常线下方画一条像这样的超宽线,即使它是不可见的,它也会响应命中测试。
In WPF, you can draw with transparent colors (with 0 for alpha channel). If you draw an extra wide line like this below the normal one, that will respond to hittests, even though it's invisible.