简体   繁体   English

多边形批注的C#OxyPlot文本位置

[英]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. 作为StartpointEndpoint的的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. 因为每个PolygonAnnotationText已经通过TextHorizontalAlignmentTextVerticalAlignment印刷在中间, TextVerticalAlignment我认为将TextPosition用作相应StartpointEndpointDataPoint是一个好主意。 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM