14

Nokia 820 vs Nokia 635 below you'll see a screen running in Windows Phone 8.1 one 2 devices. Both are claiming to have Viewport Width and Height of 800x480 however as you can see from the image the 635's nav buttons are overlapping the game area.

I have checked various properties in GraphicsDevice.Adapter and GraphicsDevice.Viewport, but they are both the same!

The screen is running within C# UWP Monogame code. I set the PrefferedBackBufferWidth and Height to 480x800.

How can you tell if the nav buttons with take up part of the screen?

Paul Marques
  • 604
  • 4
  • 15

2 Answers2

12

I will expand the answer further.

In windows phone 8.1, you have two ApplicationViewBoundsMode enum values.

  • UseVisible, pages inside application will use only the visible area excluding StatusBar, application bar and Soft navigation buttons.

    enter image description here

To make your app use ApplicationViewBoundsMode.UseVisible option, add the following in app.xaml.cs before `Windows.Current.Activate();

#if WINDOWS_PHONE_APP
        ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
#endif
  • UseCoreWindow, lay out the window's content within the region occupied by the core window (that is, including any occluded areas- including soft navigation buttons). enter image description here

To make your app use ApplicationViewBoundsMode.UseCoreWindow option, add the following in app.xaml.cs before Windows.Current.Activate();

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

In some cases, developers may want to use UserCoreWindow option to show content under app bar but as a side effect navigation soft buttons will occlude parts of your page to resolve it, follow the next solution.

You can listen for ApplicationView.GetForCurrentView().VisibleBoundsChanged in WindowsPhone and update the margin of your page.

Here is an article written by Joost van on fixing this issue (and a behavior that you can use out of the box)

Quoting the issue explanation from the above link

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.

And a snippet from his solution where he updates the margin of page

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;
  }
}
  • I'm just not able to get this to work with my universal project (windows/windows phone 8.1) using the monogame api. in the coming months I will be looking at this again when I migrate the code to a different game api using windows/window phone 10 in vs2015. – Paul Marques Jan 08 '16 at 19:12
  • In fact I just tried my code in the new Windows Phone 10.0.10586.0 emulator in Visual Studio 2013 and it seems to be fine in that. I'm going to make the assumption that new devices will work fine, by my old 635 perhaps never will. – Paul Marques Jan 08 '16 at 19:49
  • I expanded the answer further, can you try to use ApplicationViewBoundsMode.UseVisible and tell me if it works for you? if not can you tell me what issue you faced with the solution in the above link to help you? Regarding Windows Phone 10.0.10586.0 emulator , are you sure it's soft buttons? did you turn it on from Emulator WXGA->Tools->Sensors->Software Buttons – Ahmed Rashad Mohamed Jan 08 '16 at 20:27
  • 1
    Actually you're right that I was running the wrong emulator. When I tried the WXGA one and enabled the software buttons it still fails in new wp10 emulators :( – Paul Marques Jan 09 '16 at 11:13
  • ApplicationViewBoundsMode.UseVisible & UseCoreWindow make no difference in my app because its using monogame. However, querying the VisibleBounds is giving a height of 586 as opposed to the RenderSize of 640 - so that will definitely help. I will have to alter my draw() to cater for this lost space as well the touch points all of which was based on the available space. – Paul Marques Jan 09 '16 at 11:18
  • Well, I think your approach of querying the available height instead of hard-wiring will work, Good luck working on it. – Ahmed Rashad Mohamed Jan 09 '16 at 12:55
  • I don't understand - MSDN tells me these methods (`SetDesiredBoundsMode()`) and properties (`VisibleBounds`) are available on Win 8.1 aswell as WP 8.1, but they are simply missing in my shared project. Am I missing something? – NoHarmDan Apr 03 '16 at 22:25
  • @NoHarmDan It's available only in WP8.1 and not Win8.1 so inside your shared code in app.cs, you have to check for #if WINDOWS_PHONE_APP #endif as indicated in the answer when using 'SetDesiredBoundsMode'. Plus you don't need it in Windows as there are no soft navigation bars. – Ahmed Rashad Mohamed Apr 05 '16 at 07:47
  • @Ahmed I did do that, but it didn't compile anyway. Did it again now and it compiles. I must've had a typo before. But nevertheless, it has absolutely no effect - the window still renders under the button bar. – NoHarmDan Apr 07 '16 at 13:17
  • It makes no difference for me in UWP app in Windows 10 phone emulator – Mike Keskinov Mar 23 '17 at 00:29
0

to hide the navigation bar in your monogame windows phone 8.1 game add the following code in your app.xaml.cs file under InitializePhoneApplication() method

 RootFrame = new PhoneApplicationFrame();

        //I have set it to RootVisual to hide navigationbar
        RootFrame.FullScreen = true;
        if (RootVisual != RootFrame)
            RootVisual = RootFrame;
plamut
  • 3,085
  • 10
  • 29
  • 40
TMSAL
  • 103
  • 8
  • what about on a device that only has software buttons, such as the Nokia 635? I haven't tried what you suggest, but I suspect it would not work. – Paul Marques Jan 13 '16 at 21:43