出色地!!因此,在互联网上进行了大量搜索之后,在 stackoverflow 上看到类似的答案和建议,似乎计算 UWP 应用程序中的任务栏高度并不是那么直接或简单的任务。但是对于我的情况我最终得到了这个解决办法效果很好。但我会继续寻找合适的方法。假设我的屏幕分辨率是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)当我在任务栏锁定(可见)的情况下运行应用程序时,我得到view.VisibleBounds.Height as 828.
2)当我使用 TaskBar AutoHidden(Invisible) 运行应用程序时,我得到view.VisibleBounds.Height as 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.Visible Bounds.Height(这是828)
如果我将以上三者结合起来,我会使用以下代码行得到 900(所需高度):
_viewModel.ActualScreenHeight = view.VisibleBounds.Height + titleBarHeight + taskBarHeight;
我希望它对其他人也有用。
谢谢!!