我正在计算屏幕宽度和高度,它似乎已关闭。看起来状态栏的高度或宽度包含在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
事件进行更新。
有什么想法吗?
答案 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.