如何获取窗口在屏幕上的绝对位置?
在 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/