[UWP][C#]有没有办法获取Windows.UI.Xaml.Shapes.Rectangle的坐标(左,顶点)?

[UWP][C#]Is there a way to get coordinates(left,top Points) of Windows.UI.Xaml.Shapes.Rectangle?

我正在使用 C# 为 UWP 构建一个 pdf 查看器,我正在尝试获取 Windows.UI.Xaml.Shapes.Rectangle 的坐标。 在 .net 框架中,System.Drawing.Rectangle 有两个属性(X,Y)来获取左上角的坐标。我想在 UWP 中使用 Windows.UI.Xaml.Shapes.Rectangle.

做同样的事情

[UWP][C#]Is there a way to get coordinates(left,top Points) of Windows.UI.Xaml.Shapes.Rectangle?

您可以使用 TransformToVisual 获取 Window.Current.Content 的相对坐标。详情请参考以下代码。

var trc = TestRect.TransformToVisual(Window.Current.Content);
Point screenCoords = trc.TransformPoint(new Point(0, 0));