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

如何使用C#代码检测UWP应用运行在Xbox还是PC设备上

C#检测UWP应用运行在Xbox/PC设备的实现方案

你需要的Xbox设备判断逻辑可以通过UWP提供的设备族标识API实现,具体代码如下:

基础实现方案

首先封装一个通用的设备判断辅助类:

using Windows.System.Profile;

public static class DeviceEnvironment
{
    /// <summary>
    /// 判断当前应用是否运行在Xbox设备上
    /// </summary>
    public static bool IsXbox => 
        AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox";
}

调用方式完全匹配你期望的写法:

if (DeviceEnvironment.IsXbox)
{
    // 执行Xbox专属逻辑
}

常见设备族枚举值参考

如果需要扩展更多设备的判断,可以对照以下系统返回的DeviceFamily值:

  • Windows.Desktop:普通Windows PC设备
  • Windows.Xbox:Xbox主机设备
  • Windows.Mobile:Windows Phone移动设备
  • Windows.IoT:Windows物联网设备
  • Windows.Team:Surface Hub设备

增强版实现(可选)

如果需要同时兼容Xbox特有的交互模式判断(避免部分特殊场景误判),可以结合交互模式二次校验:

using Windows.System.Profile;
using Windows.UI.ViewManagement;

public static class DeviceEnvironment
{
    public static bool IsXbox
    {
        get
        {
            // 先校验设备族
            if (AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.Xbox")
                return false;
            // 额外校验Xbox默认的手柄交互模式
            var interactionMode = UIViewSettings.GetForCurrentView().UserInteractionMode;
            return interactionMode == UserInteractionMode.Controller;
        }
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 13:09:04