c# - Windows Phone 导航按钮与屏幕分辨率重叠

标签 c# windows-phone monogame uwp

Nokia 820 vs Nokia 635下面您将看到在 Windows Phone 8.1 one 2 设备中运行的屏幕。两者都声称具有 800x480 的视口(viewport)宽度和高度,但是正如您从图像中看到的那样,635 的导航按钮与游戏区域重叠。

我检查了 GraphicsDevice.Adapter 和 GraphicsDevice.Viewport 中的各种属性,但它们都是一样的!

屏幕在 C# UWP Monogame 代码中运行。我将 PrefferedBackBufferWidth 和 Height 设置为 480x800。

如何判断导航按钮是否占据了屏幕的一部分?

最佳答案

我会进一步扩展答案。

在 Windows Phone 8.1 中,您有两个 ApplicationViewBoundsMode 枚举值。

  • UseVisible,应用程序内部的页面将仅使用不包括 StatusBar、应用程序栏和软导航按钮的可见区域。

    enter image description here

要让您的应用使用 ApplicationViewBoundsMode.UseVisible 选项,请在 app.xaml.cs 中的 `Windows.Current.Activate(); 之前添加以下内容;

#if WINDOWS_PHONE_APP
        ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
#endif
  • UseCoreWindow,在核心窗口占据的区域内布置窗口的内容(即,包括任何遮挡区域 - 包括软导航按钮)。 enter image description here

要让您的应用使用 ApplicationViewBoundsMode.UseCoreWindow 选项,请在 app.xaml.cs 中的 Windows.Current.Activate(); 之前添加以下内容

#if WINDOWS_PHONE_APP
        ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
#endif

在某些情况下,开发人员可能希望使用 UserCoreWindow 选项在应用栏下显示内容,但作为副作用,导航软按钮会遮挡部分页面以解决此问题,请遵循下一个解决方案。

您可以在 WindowsPhone 中监听 ApplicationView.GetForCurrentView().VisibleBoundsChanged 并更新页面边距。

这是一个 article由 Joost van 撰写,用于解决此问题(以及您可以开箱即用的行为)

引用上面链接的问题解释

If the application view bound mode is set to ApplicationViewBoundsMode.UseCoreWindow in App.Xaml.cs the phone reports the whole screen size – not only the part that is normally taken by the status bar on top and the application bar at the bottom, but also the part that is used by the button bar.

以及他更新页边距的解决方案中的一个片段

void KeepInViewBehaviorVisibleBoundsChanged(ApplicationView sender, object args)
{
  UpdateBottomMargin();
}

private void UpdateBottomMargin()
{
  if (WindowHeight > 0.01)
  {
    var currentMargins = AssociatedObject.Margin;

    var newMargin = new Thickness(
      currentMargins.Left, currentMargins.Top, currentMargins.Right,
      originalBottomMargin + 
        (WindowHeight - ApplicationView.GetForCurrentView().VisibleBounds.Bottom));
    AssociatedObject.Margin = newMargin;
  }
}

关于c# - Windows Phone 导航按钮与屏幕分辨率重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33069252/

相关文章:

c# - 使用SoundEffectInstance作为背景音乐可以接受吗?

c# - 从 Visual Studio 2013 运行测试会构建不相关的项目

c# - 在 windows phone 8.1 中,Windows phone 项目和 silverlight 项目有什么区别?

c# - 如何将 JSON 数组转换为 List<>?

c# - GameTime.ElapsedGameTime 没有改变

xamarin - 有 F# Monogame 模板吗?

c# - 在 using 语句中创建的对象会怎样?

c# - 如何将字符串传递给 UWP 应用程序并从 Windows 窗体应用程序启动它

c# - 使用 CMS 进行 ASP.NET MVC 项目的最佳方法是什么

visual-studio-2010 - 我是否需要花费 99 美元的开发者帐户来为我自己的 Windows Phone 开发应用程序?