c# UWP 窗口在屏幕上的位置问题

标签 c# uwp location window screen

如何获取窗口在屏幕上的绝对位置?

在 WPF 中有:

var location = myTextBlock.PointToScreen(new Point(0,0));

但在 UWP 中我找不到类似的东西......

对此有什么想法吗?

最佳答案

试试这个:

假设 ctl 是您要查找其绝对屏幕坐标的控件:

Dim ttv As GeneralTransform = ctl.TransformToVisual(Window.Current.Content)
Dim WindowCoords As Point = ttv.TransformPoint(New Point(0, 0))
Dim ScreenCoordsX as double = WindowsCoords.X + ApplicationView.GetForCurrentView().VisibleBounds.Left
Dim ScreenCoordsY as double = WindowsCoords.Y + ApplicationView.GetForCurrentView().VisibleBounds.Top

您可以添加 ctl.ActualWidth 以找到右侧,但如果您已将 ScaleTransform 应用于控件,则必须将 ActualWidth 乘以相同的比例,因为 ActualWidth 不受转换的影响。

关于c# UWP 窗口在屏幕上的位置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42721602/

相关文章:

c# - Solaris 不使用 Renci.SshNet 通过远程 session 返回某些命令的输出

c# - Amazon .NET AWS SDK 的 AmazonS3 线程安全吗?

c# - Entity Framework 4.1 - RequiredAttribute 的真正含义是什么?

windows - UWP map 控制 : distinction between user- and app-manipulation

c# - 使用 UWP broadFileSystemAccess 受限权限时无法读取/写入文件

android - 服务 vs IntentService 在位置跟踪服务的情况下

android - 在openstreetmap android中单击时绘制标记

c# - MigraDoc - 如何避免段落之间换行

c# - Windows 10 UWP 应用程序 c# - 在组合框中禁用鼠标滚轮

快速适配注释