【问题标题】:c# UWP window location on screen issuec# UWP 窗口位置在屏幕上的问题
【发布时间】:2017-03-10 15:08:34
【问题描述】:

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

在 WPF 中有:

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

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

对此有什么想法吗?

【问题讨论】:

  • 可能重复:stackoverflow.com/a/12388558/7604843 试试那里找到的答案。
  • 我正在获取页面中控件的坐标。我需要屏幕上的窗口坐标...
  • 答案是给你页面坐标?
  • 您是否将Window 传递给TransformToVisual 调用?
  • 在 HoloLens 上拥有“绝对坐标”意味着什么?

标签: c# uwp location window screen


【解决方案1】:

试试这个:

假设 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 不受变换的影响。

【讨论】:

    【解决方案2】:

    您无法在当前 UWP API 中获取或设置窗口在屏幕上的位置。你只能部分控制它的大小。

    您可以使用AdjacentToLeftDisplayEdgeAdjacentToRightDisplayEdge 来查询窗口是否捕捉到屏幕的一侧。也可以使用IsFullScreenMode属性查询应用是否全屏。

    【讨论】:

    • 你可以得到它。使用:ApplicationView.GetForCurrentView().VisibleBounds 就是不能设置。
    猜你喜欢
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    相关资源
    最近更新 更多