Window.Current.Bounds高度没有状态栏,每个方向

时间:2015-06-24 07:42:12

标签: c# xaml windows-phone-8.1

我正在计算屏幕宽度和高度,它似乎已关闭。看起来状态栏的高度或宽度包含在Window.Current.Bounds

肖像的高度为32px,横向为72px,但似乎可以扩展,因为Windows.UI.ViewManagement.StatusBar.GetForCurrentView().OccludedRect.Height显示为26.6667和60。

获取屏幕高度和宽度的最佳方法是什么,不包括状态栏?

private void LayoutControls()
{
    var bounds = Window.Current.Bounds;
    var scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
    var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView().OccludedRect;

    if (bounds.Width < bounds.Height)
    {
        // Portrait
        bounds.Height -= 32d / scale;
    }
    else
    {
        // Landscape
        bounds.Width -= 72d / scale;
    }

    // do something with new bounds
}

它永远不会是32而永远不会是72. / scale适用于某些DPI手机但不适用于1080p。调查Windows.UI.ViewManagement.StatusBar.GetForCurrentView().OccludedRect会给出正确的高度,但不会使用Window.Current.SizeChanged事件进行更新。

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

尝试

Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Height;

正如文件所说:

Gets the visible region of the window (app view). The visible region is the region not occluded by chrome such as the status bar and app bar.