簡體   English   中英

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

[英]C# OxyPlot Textposition of PolygonAnnotation

我在PolygonAnnotation顯示了兩個PlotModel 我想通過一個ArrowAnnotation連接它們。 作為StartpointEndpoint的的ArrowAnnotation我想有一個規定的相應的點PolygonAnnotation ,不被點擊的位置。 因為每個PolygonAnnotationText已經通過TextHorizontalAlignmentTextVerticalAlignment印刷在中間, TextVerticalAlignment我認為將TextPosition用作相應StartpointEndpointDataPoint是一個好主意。 不幸的是TextPosition始終等於{n. def. n. def.} {n. def. n. def.} {n. def. n. def.}

任何想法如何得到的位置Text或其他定義的Datapoint一個內PolygonAnnotation

不知道這是否是最好的方法,但是您可以嘗試通過可視樹進行操作。

    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