Windows 10 移动版 - 无法隐藏状态栏(状态栏在上下文中不存在) [英] Windows 10 Mobile - cannot hide status bar (StatusBar doesn't exist in context)

查看:31
本文介绍了Windows 10 移动版 - 无法隐藏状态栏(状态栏在上下文中不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 Windows 10 通用应用程序中隐藏状态栏.在 WP 8.1 中,我使用 StatusBar.GetForCurrentView().HideAsync(); 来隐藏状态栏,但是这在我当前的项目(Monogame、Win10 UAP)中不起作用 - 我得到在当前上下文中找不到 StatusBar"错误(是的,我正在使用 Windows.UI.ViewManagement).我做错了什么,还是删除了这个删除 StatusBar 的选项?我应该如何在 W10M 中做到这一点?提前致谢.

I am trying to hide status bar in my Windows 10 Universal App. In WP 8.1, I was using StatusBar.GetForCurrentView().HideAsync();to hide the status bar, however this won't work in my current project (Monogame, Win10 UAP) - I get "StatusBar not found in the current context" error (yes, I am using Windows.UI.ViewManagement). Am I doing something wrong, or was this option to remove StatusBar removed? How should I do it in W10M? Thanks in advance.

推荐答案

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

The trick is that you have to add a reference to the Microsoft Mobile Extension SDK first. Then the code is the following:

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

可以通过右键单击通用项目来添加引用.选择添加引用".在参考管理器"对话框中,选择左侧的Windows Universal".选择扩展"并选中Microsoft Mobile Extension SDK...".

The reference can be added by right clicking the universal project. Select "Add reference". In the Reference Manager dialog select "Windows Universal" on the left. Choose "Extensions" and check the "Microsoft Mobile Extension SDK...".

由于这是一个通用应用程序,它将在每台设备上运行,但该 API 将仅在装有 Windows 10 的移动设备(又名手机)上可用.因此,在您实际调用应用程序接口.否则它会在运行时抛出 TypeLoadException.

As this is a universal App it will run on every device, but the API will be available only on mobile Devices (aka Phones) with Windows 10. Therefore feature-detect if this API is available at runtime before you actually call the API. Otherwise it will throw a TypeLoadException at runtime.

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

Use the Windows.Foundation.Metadata.ApiInformation Namespace to find out if the API is available. (E.g. Method IsTypePresent() . I recommend working with typeof instead of Strings here, e.g. like this:

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

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

Learn more about adaptive code here: https://channel9.msdn.com/Series/A-Developers-Guide-to-Windows-10/08

这篇关于Windows 10 移动版 - 无法隐藏状态栏(状态栏在上下文中不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆