如何在 WPF 应用程序中获取 Windows 任务栏高度?

Mah*_*man 4 .net c# wpf

我正在尝试从 WPF 应用程序获取Windows 任务栏的高度。我明白了 如何获取任务栏的位置和大小?它显示了如何找到任务栏位置而不是高度。我从How can I get the height of the windows Taskbar?得到了答案。其中说

使用 Screen 类。任务栏的区别在于其Bounds 和WorkingArea 属性。

但没有代码示例。如果这是正确的,这应该是任务栏的高度。我做对了吗?

private int WindowsTaskBarHeight => Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;
Run Code Online (Sandbox Code Playgroud)

小智 5

var toolbarHeight = SystemParameters.PrimaryScreenHeight - SystemParameters.FullPrimaryScreenHeight - SystemParameters.WindowCaptionHeight;
Run Code Online (Sandbox Code Playgroud)

这段代码适合我。我在windows 10下测试了一下。