I have a ControlTemplate
that serves as a "Bubble" popup on the AdornerLayer
of a given control.
我有一个ControlTemplate,它作为给定控件的AdornerLayer上的“Bubble”弹出窗口。
It works fine but I need to be able to calculate where it should display (middle/ bottom).
它工作正常但我需要能够计算它应该显示的位置(中间/底部)。
Instead of:
<Path Stroke="Black" Fill="Black" Data="M 15 20 L 15 0 33 20" Margin="0 1 0 0"/>
I am looking for (obviously this won't work but it illustrates what I'm trying to accomplish:
我正在寻找(显然这不起作用,但它说明了我正在努力实现的目标:
<Path Stroke="Black" Fill="Black" Data="M {TemplateBinding Left} 20 L 15 0 33 20"/>
Can this be done with a ValueConverter
? I just can't visualize a solution for some reason. I'm also open to alternatives.
可以使用ValueConverter完成吗?由于某种原因,我无法想象解决方案。我也愿意接受替代方案。
Thanks for reading and if I can provide more info please just ask.
感谢阅读,如果我能提供更多信息,请问问。
1 个解决方案
#1
7
If you want a value converter that you can use to convert a string into the path data, you might like to try the universal value converter I wrote a while back.
如果你想要一个可以用来将字符串转换成路径数据的值转换器,你可能想尝试我之前写的通用值转换器。
Alternatively, to bind to a single property, you will have to expand your geometry by adding the various geometry objects into your XAML, rather than using the string shorthand. For example ...
或者,要绑定到单个属性,您必须通过将各种几何对象添加到XAML中来扩展几何体,而不是使用字符串速记。例如 ...
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure IsClosed="True" StartPoint="10,100">
<PathFigure.Segments>
<PathSegmentCollection>
<LineSegment Point="{Binding MyPropertyPath}" />
<LineSegment Point="100,50" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
#1
7
If you want a value converter that you can use to convert a string into the path data, you might like to try the universal value converter I wrote a while back.
如果你想要一个可以用来将字符串转换成路径数据的值转换器,你可能想尝试我之前写的通用值转换器。
Alternatively, to bind to a single property, you will have to expand your geometry by adding the various geometry objects into your XAML, rather than using the string shorthand. For example ...
或者,要绑定到单个属性,您必须通过将各种几何对象添加到XAML中来扩展几何体,而不是使用字符串速记。例如 ...
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure IsClosed="True" StartPoint="10,100">
<PathFigure.Segments>
<PathSegmentCollection>
<LineSegment Point="{Binding MyPropertyPath}" />
<LineSegment Point="100,50" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>