[英]C# OxyPlot Textposition of PolygonAnnotation
I am having two PolygonAnnotation
shown on a PlotModel
. 我在PolygonAnnotation
显示了两个PlotModel
。 I want to connect them via one ArrowAnnotation
. 我想通过一个ArrowAnnotation
连接它们。 As Startpoint
and Endpoint
of the ArrowAnnotation
I want to have a defined point of respective PolygonAnnotation
, not the clicked position. 作为Startpoint
和Endpoint
的的ArrowAnnotation
我想有一个规定的相应的点PolygonAnnotation
,不被点击的位置。 As the Text
of each PolygonAnnotation
is already printed in the center via TextHorizontalAlignment
and TextVerticalAlignment
I thought using TextPosition
as the DataPoint
for the respective Startpoint
or Endpoint
would be a good idea. 因为每个PolygonAnnotation
的Text
已经通过TextHorizontalAlignment
和TextVerticalAlignment
印刷在中间, TextVerticalAlignment
我认为将TextPosition
用作相应Startpoint
或Endpoint
的DataPoint
是一个好主意。 Unfortunatly TextPosition
always equals {n. def. n. def.}
不幸的是TextPosition
始终等于{n. def. n. def.}
{n. def. n. def.}
{n. def. n. def.}
. {n. def. n. def.}
。
Any ideas how to get the position of the Text
or another defined Datapoint
within a PolygonAnnotation
? 任何想法如何得到的位置Text
或其他定义的Datapoint
一个内PolygonAnnotation
?
Not sure if this is the best way, but you could try working your way through the Visual Tree. 不知道这是否是最好的方法,但是您可以尝试通过可视树进行操作。
public void FindPosition(object obj)
{
if (obj == null) return;
var plotView = (PlotView)obj;
FindTextPosition<PlotView>(plotView).FindName(plotView.Name);
}
private IEnumerable<T> FindTextPosition<T>(DependencyObject parent)
where T : DependencyObject
{
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
if (child is TextBlock text)
{
if (text.Text == "Test") // Or any identifier you could specify
{
var position = text.PointToScreen(new Point(0d, 0d));
}
}
foreach (var other in FindTextPosition<T>(child)) yield return other;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.