0

I am having two PolygonAnnotation shown on a PlotModel. I want to connect them via one ArrowAnnotation. As Startpoint and Endpoint of the ArrowAnnotation I want to have a defined point of respective PolygonAnnotation, not the clicked position. 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. Unfortunatly TextPosition always equals {n. def. n. def.}.

Any ideas how to get the position of the Text or another defined Datapoint within a PolygonAnnotation?

bolov
  • 72,283
  • 15
  • 145
  • 224
Kunibert
  • 21
  • 8

1 Answers1

0

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;
        }
    }
Anu Viswan
  • 17,797
  • 2
  • 22
  • 51