带文本框的连接线,绑定问题
我想画一条线,当我双击它时,我想在上面放置一个文本。我正在考虑将其放入内容控件中并画一条线,在顶部放置一个折叠的文本框,检测双击,显示文本框将其设置为文本块等。我遇到的唯一问题是我不知道该怎么办设置线条的坐标,因为它位于内容控件内部,因此会绘制实际的线条。我已经被困了几个小时,任何帮助将不胜感激。
基本上我需要一个具有起点和终点属性的对象,该对象具有线条的形状和内容呈现器。但我不知道该怎么做。任何指示将不胜感激。
I want to draw a line and when I double click it I want to put a text on it. I was thinking of putting it in a contentcontrol and drawing a line, put a collapsed textbox on top, detect a double click, show the textbox set it to a textblock, etc. The only problem I run into I don't know what to set the coordinates of the line since it is inside the contentcontrol, so an actual line gets drawn. i've been stuck for hours, any help would be appreciated.
Basically I need an object with a start and end point properties which has the shape of a line , with a content presenter. But I don't know how to go about doing this. Any pointers would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们也用同样的方法来标记我们的联系。如果您通过路径绘制连接,则可以使用
这种方式,您将在几何图形上拥有中心位置。现在您可以将其存储到用于定位标签的依赖属性中。当然,每次形状/几何形状改变其位置或大小时都必须调用它。
结合此控件的一个小示例。
您的 ControlTemplate 看起来像这样
现在要添加
ContentControl
功能,您可以添加 ContentPresenter 来代替 TextBox。为此,只需为您的 2 个位置添加 2 个 dp 属性。确保添加依赖属性更改处理程序以调用 UpdatePath 方法。
We do the same for labeling our connections. If you draw your connection via a path you can use
That way you would have the center position on your geometry. Now you could store this into a dependency property which you use to position the label. Of course this must be called everytime your shape/geometry changes its position or size.
a small example for a control combining this.
Your ControlTemplate would look something like that
Now to add the
ContentControl
functionality you could add the ContentPresenter in place of the TextBox.For that just add 2 dp properties for your 2 positions. Make sure to add a dependency property changed handler to call the UpdatePath method.