The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP][XBOX]trouble with the gamepad for xbox uwp package RRS feed

  • Question

  • Hi, i was having trouble with the xbox gamepad. When i test it on xbox, the B button backs out of the game but when it is tested on my desktop it doesn't. I'm trying to figure out if that is a coding error or if it was a compiling error? Either way, i don't know where i'm supposed to ask this so I'm gonna just throw it out there.

    Thanks in advance.


    Daniel Hood


    • Edited by Breeze Liu Thursday, May 31, 2018 7:13 AM add [UWP][XBOX]
    Tuesday, May 1, 2018 6:20 PM

Answers

  • Hi dhood55,

    You should implement this effect in your app's project code, in the page's code behind, such as MainPage.xaml.cs, as the code in the document that I provide you above: 

    https://docs.microsoft.com/en-us/windows/uwp/design/devices/designing-for-tv#built-in-button-support

    // This code goes in the MainPage class
    
    public MainPage()
    {
        this.InitializeComponent();
    
        // Handling Page Back navigation behaviors
        SystemNavigationManager.GetForCurrentView().BackRequested +=
            SystemNavigationManager_BackRequested;
    }
    
    private void SystemNavigationManager_BackRequested(
        object sender,
        BackRequestedEventArgs e)
    {
        if (!e.Handled)
        {
            e.Handled = this.BackRequested();
        }
    }
    
    public Frame AppFrame { get { return this.Frame; } }
    
    private bool BackRequested()
    {
        // Get a hold of the current frame so that we can inspect the app back stack
        if (this.AppFrame == null)
            return false;
    
        // Check to see if this is the top-most page on the app back stack
        if (this.AppFrame.CanGoBack)
        {
            // If not, set the event to handled and go back to the previous page in the
            // app.
            this.AppFrame.GoBack();
            return true;
        }
        return false;
    }

    Best regards,

    Breeze


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by dhood55 Wednesday, May 16, 2018 9:02 PM
    Thursday, May 10, 2018 1:40 AM

All replies

  • Hi dhood55,

    Welcome to the Developing Universal Windows apps forum! Please utilize tagging when posting to this forum, thanks!

    Do you use some special code in your UWP app? What are your  app target version and min Version? And what is your xbox system version and build? Could you clarify "when it is tested on my desktop it doesn't." ? Do you mean you connect the gamepad to your desktop and the B button will not back out your app? So what is your requirement?

    Best regards,

    Breeze


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Breeze Liu Wednesday, May 2, 2018 5:50 AM
    Wednesday, May 2, 2018 5:48 AM
  • hi, thanks for replying. So I'm not sure what I'm looking for but the package is a x64 compile and I install it onto my PC with a controller plugged into it. The target version is the 10.0.16299.0 and the minimum version is 10.0.15063.0.

    This is playing it during testing and after publishing. So, in both cases, the package on the computer doesn't back out of the game when i press B but on the xbox it does. Maybe my dev mode was set up wrong? But I'm not sure what other information to give out.

    and as far as i know i don't have any special code except for the required code for xbox sign in.


    Daniel Hood


    • Edited by dhood55 Wednesday, May 2, 2018 10:09 PM
    Wednesday, May 2, 2018 10:08 PM
  • Hi dhood55,

    Could you tell me your Xbox version? On the other way, you can try to restart the xbox or exit then reenter the develop mode again.

    Best regards,

    Breeze


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Breeze Liu Thursday, May 3, 2018 8:51 AM
    Thursday, May 3, 2018 3:01 AM
  • My xbox version is 10.0.17133.2020. But i should mention that I'm not compiling the package through the xbox console, I'm doing it through my desktop. Would that be the problem?

    Cause the problem still persists outside of my console. the game is already published and others have played with the same problem


    Daniel Hood


    • Edited by dhood55 Thursday, May 3, 2018 11:32 AM
    Thursday, May 3, 2018 11:30 AM
  • Hi dhood55,

    I can reproduce this behavior on my Xbox device and I am trying to consult whether it is the expected behavior that app will exit when user clicks B button in Xbox device. Appreciate your patience in advance.

    Best regards,

    Breeze


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Breeze Liu Friday, May 4, 2018 1:53 AM
    Friday, May 4, 2018 1:53 AM
  • Alright thank you, sorry for not responding soon, but i will be waiting. Hopefully we can figure out a resolution.

    Daniel Hood

    Sunday, May 6, 2018 8:22 PM
  • Hi dhood55,

    The B button it is translated to a “back” navigation operation. The default if the app doesn’t handle the BackRequested event is to go back to the Xbox shell. This is expected behavior. You can change this behavior by handling the SystemNavigationManager.BackRequested event and setting e.Handled to true.

    See https://docs.microsoft.com/en-us/windows/uwp/design/devices/designing-for-tv#gamepad-and-remote-control and https://blogs.msdn.microsoft.com/chuckw/2017/12/15/directx-and-uwp-on-xbox-one/ for examples.

    Best regards,

    Breeze


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Breeze Liu Tuesday, May 15, 2018 1:43 AM
    Monday, May 7, 2018 5:39 AM
  • Alright awesome! Last question, where do i implement this? do i put this in a visual studio file or my game file? I'm kind of new to publishing and i work with gamemaker so i don't really do much code outside of it than what's needed. I also don't believe the gamemaker file reads the code.

    Anyway, i know it's a silly question, but I've been looking into the docs url you sent me i just got confused on where i can use the information.


    Daniel Hood


    • Edited by dhood55 Wednesday, May 9, 2018 12:27 PM
    Wednesday, May 9, 2018 12:24 PM
  • Hi dhood55,

    You should implement this effect in your app's project code, in the page's code behind, such as MainPage.xaml.cs, as the code in the document that I provide you above: 

    https://docs.microsoft.com/en-us/windows/uwp/design/devices/designing-for-tv#built-in-button-support

    // This code goes in the MainPage class
    
    public MainPage()
    {
        this.InitializeComponent();
    
        // Handling Page Back navigation behaviors
        SystemNavigationManager.GetForCurrentView().BackRequested +=
            SystemNavigationManager_BackRequested;
    }
    
    private void SystemNavigationManager_BackRequested(
        object sender,
        BackRequestedEventArgs e)
    {
        if (!e.Handled)
        {
            e.Handled = this.BackRequested();
        }
    }
    
    public Frame AppFrame { get { return this.Frame; } }
    
    private bool BackRequested()
    {
        // Get a hold of the current frame so that we can inspect the app back stack
        if (this.AppFrame == null)
            return false;
    
        // Check to see if this is the top-most page on the app back stack
        if (this.AppFrame.CanGoBack)
        {
            // If not, set the event to handled and go back to the previous page in the
            // app.
            this.AppFrame.GoBack();
            return true;
        }
        return false;
    }

    Best regards,

    Breeze


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by dhood55 Wednesday, May 16, 2018 9:02 PM
    Thursday, May 10, 2018 1:40 AM