2D 编辑器的 WPF 线条和折线事件
我想在 WPF 中创建一个类似 2d 编辑器的应用程序,我需要知道如何执行此操作:
- 当我单击直线或折线时如何拦截事件?
- 如何检测行的结尾/开头并在行的结尾或开头显示一个小点或小框。如果我接近行尾或行首,有没有办法引发事件?
- 如何创建平移和缩放功能?我如何控制画布以实现该功能?
- 我怎样才能保持X和Y之间的纵横比和比例。我的意思是,如果我有一条长度为 5 的水平线和一条长度为 5 的垂直线,我该怎么做才能使两条线在视觉上看起来长度相同?
感谢您的回答。 爱德华多
i want to create a 2d-editor like application in WPF an i need to know how to do this:
- How can intercept the event when i click on a Line or Polyline?
- How can detect the end / beginning of a line and show a small dot or small box in the end or the beginning of the line. Is there a way to raise an event if i get close of end or the beginning of the line?
- How can i create a panning and zooming functionality? How can i control the canvas for that functionality?
- How can i maintain the aspect ratio between X and Y and the scale. I mean if i have a horizontal line of length 5 and a vertical line of length 5, what do i have to do to both lines look the same length visually?
Thanks for your answers.
Eduardo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道的不多,但我想到的想法如下,如有错误,请指正。
使用命中测试[Ref]或预定义的可扩展形状[Ref],已具有通用输入事件(例如
MouseEnter
、MouseLeave
等)要显示小点,您可以使用 装饰器。每条线 a 都有终点和起点,您可以获取它的值并为它们调整您的视觉(小点)。是的,
Adorner
可以帮助你,它们就像任何其他UIElement
一样,所以常见事件如MouseEnter
、MouseLeave
, ... 在那里。对于平移和缩放,您可以使用此处或< a href="http://www.codeproject.com/KB/WPF/zoomandpancontrol.aspx" rel="nofollow">此处 或 此处
这些线条在视觉上是相同的。只需使用形状(上面的链接)绘制它们即可。
I don't know much, but the ideas that came to my mind are as below, correct me if anything wrong.
Using Hit-Testing [Ref] or Pre-defined extendable Shapes [Ref], which already have common Input events (like
MouseEnter
,MouseLeave
, ...)For showing a small dot, u can use Adorners. Every line a has end and start point, u can just get it's value and adjust your visual (small dot) for them. Yes,
Adorner
can help u, they are just like any otherUIElement
, so commons events likeMouseEnter
,MouseLeave
, ... are there.For panning and zooming, u can use the code from here or here or here
The lines will be visually same. Just draw them using Shapes (link above).