Developing for Modern Windows

Tips, tricks, and guides for developing on modern Windows platforms

UWP on XBox Tips and Tricks Part 2

In the last couple of days I’ve been deep into porting an app to work on the XBox One. I made a post with a bunch of XBox UWP tips, but in the time since then I’ve discovered a few more tips.

So here is my second set of tips for developing UWP apps for XBox One.

Tip #1: Spacebar == A Button, B == ESC/Back

When building your own controls, you will find that the click and tapped events won’t work with the XBox controller. For your own controls, hook into the KeyDown event. When the user presses the XBox ‘A’ button, this translates to the spacebar (VirtualKey,Space) in UWP apps. So add a handler for KeyDown, check if VirtualKey.Space was the key pressed, then handle the press.

The ‘B’ button is mapped to the ESC key and also the Back event.

Tip #2: Force the Screen Size when Building

If you are working on your XBox layout on a PC and testing on the PC, it helps to force the window to the correct size for XBox when the application launches. This simulates the layout on a real XBox.

The following code will (try to) force the app’s size to match the 960×540 effective pixels size for XBox:

  ApplicationView.PreferredLaunchViewSize = new Size(960, 540);
  ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

Remember that you still need to test the app on a real console for best results, and you should wrap that code if you don’t want it to run on different devices or in the release build.

Tip #3: Deployment Troubleshooting

Some Microsoft experts shared a lot of tips in a great Expert Panel on Channel9 (https://channel9.msdn.com/events/Xbox/App-Dev-on-Xbox/Expert-panel). Among the tips were these three troubleshooting steps to try if you are having difficulty deploying your app to an XBox:

  1.  “Registration Failed” error – reinstall the application. Uninstall, then re-deploy from Visual Studio.
  2. “Network Timeout” error – restart the XBox.
  3. Try closing and re-opening Visual Studio, then try deploying again.

Tip #4: Sounds Like XBox

When you use XBox apps, you will notice there are specific system sounds when you scroll through items or press a button. These system sounds are built into the platform, and all it takes to enable them is one line of code:

ElementSoundPlayer.State = ElementSoundPlayerState.On;

This should work for default controls and interactions, but for custom UI you may want to manually play the sounds as your app requires:

ElementSoundPlayer.Play(ElementSoundKind.Invoke);

That line of code plays the ‘invoke’ sound (i.e. the sound when you select an item by tapping ‘A’. You can of course choose from the available sounds using Intellisense in Visual Studio.

Tip #5: Handle Snapping

Unfortunately, UWP developers can’t implement snapping their apps to the side of the screen on XBox. Hopefully Microsoft will implement this is a future update. Your apps are still subject to having another app snapped beside it, however. This means you need to design your layouts to adapt to the smaller window your app will have while a part of the screen is taken up by a snapped app. If you’re using good design practices already, this shouldn’t be a problem, but you need to be aware of it.

Try snapping an app when you test your own apps on an XBox console to make sure your layouts adapt properly.

Tip #6: Manually Modify Navigation

Navigation with an XBox controller usually works fine, but you can manually state which control navigation moves to when the user moves around the UI.

The XYFocus[direction] properties in XAML let you set which control is the next in the specified direction, for example:

<Button Name=“ButtonOne” Content=“Click Me” XYFocusRight=“{x:Bind ButtonTwo}” />

In that example, regardless of where ButtonOne and ButtonTwo are (and regardless of what is in between or around them), when the user moves right from ButtonOne, focus will go to ButtonTwo.

You can use this to ‘dodge’ UI that doesn’t require focus or to tweak the automatic behaviour where it doesn’t quite feel intuitive.

 

Tip #7: Roaming Settings Not Supported

At the time of writing, roaming settings are not supported on XBox. While this will probably change, for now you will have to work around it if your app relies on roaming settings.

 

Leave a Reply

Your email address will not be published.