title: How can a UWP/C# app sign in an XBox user and display gamertag?
body: <p>I am trying to resubmit a UWP app (written in C#/XAML) into the Microsoft store so that it supports "Windows 10 Xbox" in addition to the previously supported Windows Desktop and Windows Phone.  I can deploy (using Visual Studio 2017) and run the app on my Xbox One console in Developer Mode with no problems.  When I submit to the store, I get the following error: </p>
  
  <blockquote>
    <p>Because your game uses Xbox Live, it must:<br>
       · Create at least one active user and sign the user into Xbox.<br>
       · Display the user’s Xbox gamertag as the primary display and profile name. </p>
    
    <p>Please add this behavior and resubmit your game.</p>
  </blockquote>
  
  <p>I am looking for a minimal C#/XAML example that shows me how to solve this submission problem.</p>
  
  <p><a href="https://stackoverflow.com/questions/43037348/accessing-raw-gamer-profile-picture">The post on "Accessing Raw Gamer Profile Picture"
  </a> seems to indicate that I can take care of the login by doing something like this:</p>
  
  <pre><code>if (App is running on Xbox)
  {
      XboxLiveUser user = new XboxLiveUser();
      SignInResult result = await user.SignInAsync(); 
  }
  </code></pre>
  
  <p>but I'm not sure if this is correct, or how I would determine that the app is running on Xbox.</p>
  
  <p>Also, I would like to know how and where I am supposed to display the user's gamertag.  Can I just display it anywhere in the XAML?  Alternatively, is there some special Xbox api I need to call to display this?</p>
  
  <p>In short, I need a very simple C#/XAML example that shows how to do the minimal requirements of checking to see if the app is running on Xbox, logging in the user, and then displaying the user's gamertag in the appropriate place, so that I satisfy the Microsoft Store requirements.</p>
  
  <p><strong>Update:</strong>
  I did the following:</p>
  
  <p>Using Nuget Package Manager, I installed Microsoft.Xbox.Live.SDK.WinRT.UWP\</p>
  
  <p>In the project, I created an xboxservices.config file following <a href="https://docs.microsoft.com/en-us/windows/uwp/xbox-live/get-started-with-creators/develop-creators-title-with-visual-studio#4-associate-your-visual-studio-project-with-your-xbox-live-enabled-title" rel="nofollow noreferrer">Section 6 of these instructions</a></p>
  
  <p>I created a TextBlock control at upper left side of my screen, and passed it in to the following function to display the gamertag:</p>
  
  <pre><code>public static async void InitializeXboxGamer(TextBlock gamerTagTextBlock)
  {
      if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily.Contains("Xbox"))
      {
          XboxLiveUser user = new XboxLiveUser();
          SignInResult result = await user.SignInSilentlyAsync(Window.Current.Dispatcher);
          if (result.Status == SignInStatus.UserInteractionRequired)
          {
              result = await user.SignInAsync(Window.Current.Dispatcher);
          }
          gamerTagTextBlock.Text = user.Gamertag;
          gamerTagTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
      }
      else
      {
          gamerTagTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
      }
  }
  </code></pre>
  
  <p>However, this still failed to pass submission tests with the following error:</p>
  
  <blockquote>
    <p>App Policies: 10.13.5 Xbox Live Active User and Gamertag</p>
    
    <p>Notes To Developer</p>
    
    <p>Because your game uses Xbox Live, it must:  · Create at least one
    active user and sign the user into Xbox.   · Display the user’s Xbox
    gamertag as the primary display and profile name. Please add this
    behavior and resubmit your game.   You can view the Xbox Live
    documentation for more information. Your game may not appear in the
    Creators Collection until this has been resolved.</p>
    
    <p>Tested Devices: Windows 10 Desktop, Windows 10 Xbox</p>
  </blockquote>
  
  <p>Any ideas on what I'm doing wrong here?</p>