嗯!!因此,在互联网上进行了大量搜索后,在 stackoverflow 和建议上看到了类似的答案,看来在 UWP 应用程序中计算任务栏高度并不是那么直接或简单的任务。但是,对于我的情况,我最终得到了这个 workaround,它工作正常。但我会继续寻找合适的方法。假设我的屏幕分辨率是 1600x900 ,那么这就是我所做的:
private void GetScreenDimension()
{
//To get Screen Measurements e.g. height, width, X,Y...
ApplicationView view = ApplicationView.GetForCurrentView();
//Getting the Window Title Bar height(In my case I get :Top=32,Bottom=860)
double titleBarHeight = view.VisibleBounds.Top;
//Getting the TaskBar Height
double taskBarHeight = view.VisibleBounds.Top + (view.VisibleBounds.Top / 4);
//Getting the workable Height of the screen ( excluding Task Bar Height)
double availableheight = GridTimelineContent.ActualHeight - taskBarHeight;
double availablewidth = GridTimelineContent.ActualWidth;
if (_viewModel != null)
{
_viewModel.AvailableHeight = availableheight;
_viewModel.AvailableWidth = availablewidth;
//Getting the actual Physical height (i.e including TitleBar Height and Task Bar Height, gives 900 in my case which is what I wanted)
_viewModel.ActualScreenHeight = view.VisibleBounds.Height + titleBarHeight + taskBarHeight;
_viewModel.PageWidth = (this as Page).ActualWidth;
}
}
请注意:
1) 当我使用 TaskBar Locked(visible) 运行应用程序时,我得到 view.VisibleBounds.Height 为 828。
2) 当我使用 TaskBar AutoHidden(Invisible) 运行应用程序时,我得到 view.VisibleBounds.Height 为 868。
这给了我一个想法,900-868=32 可能是标题栏高度,当我在隐藏任务栏后从 828 跳到 868 时,意味着 868-828=40 可以是任务栏高度。
结论:
标题栏高度 = view.VisibleBounds.Top (即 32)
任务栏高度 = view.VisibleBounds.Top (即 32) + (view.VisibleBounds.Top / 4)(即 8); (32+8 = 总共 40 个)
剩余高度 = view.VisibleBounds.Height (即828)
如果我结合以上三个,我使用这行代码得到 900 (Required Height):
_viewModel.ActualScreenHeight = view.VisibleBounds.Height + titleBarHeight + taskBarHeight;
我希望它对其他人也有用。
谢谢!!