[英]C# OxyPlot Textposition of PolygonAnnotation
我在PolygonAnnotation
顯示了兩個PlotModel
。 我想通過一個ArrowAnnotation
連接它們。 作為Startpoint
和Endpoint
的的ArrowAnnotation
我想有一個規定的相應的點PolygonAnnotation
,不被點擊的位置。 因為每個PolygonAnnotation
的Text
已經通過TextHorizontalAlignment
和TextVerticalAlignment
印刷在中間, TextVerticalAlignment
我認為將TextPosition
用作相應Startpoint
或Endpoint
的DataPoint
是一個好主意。 不幸的是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.