Windows 10 Mobile - 无法隐藏状态栏(StatusBar 在上下文中不存在)

Windows 10 Mobile - cannot hide status bar (StatusBar doesn't exist in context)

我想在我的 Windows 10 通用应用程序中隐藏状态栏。在 WP 8.1 中,我使用 StatusBar.GetForCurrentView().HideAsync(); 来隐藏状态栏,但这在我当前的项目(Monogame,Win10 UAP)中不起作用 - 我收到 "StatusBar not found in the current context" 错误(是的,我正在使用 Windows.UI.ViewManagement). 我做错了什么,或者这个删除 StatusBar 的选项被删除了吗?我应该如何在 W10M 中进行? 提前致谢。

诀窍是您必须先添加对 Microsoft Mobile Extension SDK 的引用。 那么代码如下:

StatusBar statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
await statusBar.HideAsync();

可以通过右键单击通用项目来添加引用。 Select "Add reference"。在 Reference Manager 对话框左侧 select "Windows Universal"。选择 "Extensions" 并勾选 "Microsoft Mobile Extension SDK...".

由于这是一个通用应用程序,它将 运行 在每台设备上使用,但 API 将仅在具有 Windows 10 的移动设备(又名手机)上可用。因此功能- 在您实际调用 API 之前的 运行 时间检测此 API 是否可用。否则它将在 运行 时抛出 TypeLoadException。

使用 Windows.Foundation.Metadata.ApiInformation 命名空间查明 API 是否可用。 (例如方法 IsTypePresent() 。 我建议在这里使用 typeof 而不是 Strings,例如像这样:

var isStatusBarPresent = ApiInformation.IsTypePresent(typeof(StatusBar).ToString());

在此处了解有关自适应代码的更多信息:https://channel9.msdn.com/Series/A-Developers-Guide-to-Windows-10/08