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

如何在Xbox端UWP WebView应用中禁用默认光标并使用手柄导航?

解决UWP WebView应用在Xbox上显示默认光标问题

以下是针对该问题的有效解决步骤:

1. 全局禁用应用的指针要求

修改App.xaml.cs中的RequiresPointerMode为Never,确保应用全局不触发指针请求:

public App() {
    this.InitializeComponent();
    this.RequiresPointerMode = Windows.UI.Xaml.ApplicationRequiresPointerMode.Never;
    this.Suspending += OnSuspending;
}

2. 正确设置Page与WebView的指针属性

修正MainPage.xaml的Page标签,将RequiresPointer="Never"设为有效属性,同时给WebView也添加该属性:

<Page
    x:Class="App2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    RequiresPointer="Never"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <WebView 
            Source="https://luser.github.io/gamepadtest/"
            RequiresPointer="Never">
        </WebView>
    </Grid>
</Page>

3. 隐藏WebView内部网页的光标

WebView加载的网页可能自带光标样式,需通过注入CSS强制隐藏:
在MainPage.xaml.cs中给WebView添加NavigationCompleted事件处理:

private void WebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
    if (args.IsSuccess)
    {
        string hideCursorScript = @"
            var style = document.createElement('style');
            style.textContent = '* { cursor: none !important; }';
            document.head.appendChild(style);
        ";
        sender.InvokeScriptAsync("eval", new[] { hideCursorScript });
    }
}

同时在MainPage.xaml的WebView标签中绑定事件:

<WebView 
    Source="https://luser.github.io/gamepadtest/"
    RequiresPointer="Never"
    NavigationCompleted="WebView_NavigationCompleted">
</WebView>

4. 确保Xbox手柄导航支持

在Package.appxmanifest中添加游戏手柄设备能力,保证手柄导航正常:

<Capabilities>
    <DeviceCapability Name="gamepad" />
</Capabilities>

完成以上步骤后重新部署应用到Xbox,光标会被完全隐藏,且可通过手柄正常导航。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 00:07:41