You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已连接无线Xbox手柄但UWP中Gamepad.Gamepads为空,请求技术排查

Fixing "Sequence contains no elements" with Xbox Wireless Controller in UWP Apps

Hey Jacob, sorry to hear you're stuck on this error—let's walk through the most likely fixes since your controller works elsewhere, so it's almost certainly a UWP-specific setup issue.

1. You're Missing the Required Device Capability

UWP apps need explicit permission to access game controllers, even if the system recognizes the device. If you haven't added this, your app can't see the controller at all.

To fix this:

  • Open your Package.appxmanifest file.
  • Either use the visual editor: Go to the Capabilities tab and check the Game Controller box.
  • Or edit the XML directly, add this inside the <Capabilities> section:
    <DeviceCapability Name="gameController"/>
    

Save the manifest and rebuild your app—this is the most common fix for this exact error.

2. You're Trying to Access the Controller Too Early

The Gamepad.Gamepads collection might not populate immediately when your app starts, even if the controller is already connected. Calling First() on an empty collection throws that "Sequence contains no elements" error.

Instead of grabbing the controller on app launch, use the built-in events to react when a controller connects:

using Windows.Gaming.Input;

// Register these events when your app initializes (e.g., in MainPage constructor)
Gamepad.GamepadAdded += OnGamepadAdded;
Gamepad.GamepadRemoved += OnGamepadRemoved;

private void OnGamepadAdded(object sender, Gamepad e)
{
    // Now you have a valid controller reference to work with
    var connectedGamepad = e;
    // Start reading input here or store the reference for later
}

private void OnGamepadRemoved(object sender, Gamepad e)
{
    // Handle disconnection if needed
}

If you still want to check for existing controllers at launch, always guard against empty collections first:

if (Gamepad.Gamepads.Any())
{
    var gamepad = Gamepad.Gamepads.First();
    // Your input logic here
}
else
{
    // Show a message asking the user to connect a controller
}

3. Re-Pair Your Bluetooth Controller

Even if the controller shows up in Bluetooth settings, sometimes the UWP subsystem doesn't recognize the connection properly. Try re-pairing to refresh the link:

  • Hold the pairing button on top of the controller until the Xbox logo flashes.
  • Go to Windows Settings > Bluetooth & devices > Add device > Bluetooth, and re-select your controller.
    Wait for the pairing to complete fully before launching your app again.

4. Update Your Windows Version

Older builds of Windows 10 had bugs with UWP access to Xbox Wireless Controllers. Make sure you're on the latest stable Windows 10/11 update—this can resolve low-level compatibility issues that nothing else fixes.

Give these steps a try, and let me know if you still run into issues!

内容的提问来源于stack exchange,提问作者Jacob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:15:42