【发布时间】:2020-04-10 15:13:05
【问题描述】:
我正在使用 C# 为 UWP 构建一个 pdf 查看器,并且我正在尝试获取 Windows.UI.Xaml.Shapes.Rectangle 的坐标。
在 .net 框架中,System.Drawing.Rectangle 有两个属性(X,Y)来获取上、左坐标。我想在 UWP 中使用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#]有没有办法获取Windows.UI.Xaml.Shapes.Rectangle的坐标(左、顶点)?
您可以使用TransformToVisual 获取Window.Current.Content 的相对坐标。具体请参考以下代码。
var trc = TestRect.TransformToVisual(Window.Current.Content);
Point screenCoords = trc.TransformPoint(new Point(0, 0));
【讨论】: