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

OpenSilver手机端Tapped事件未触发,求兼容点击触摸的事件方案

OpenSilver中TextBlock点击/触摸事件兼容方案

在OpenSilver开发场景下,Tapped事件在移动端普通浏览模式下存在触发失效的问题,推荐使用**PointerPressed事件**来统一处理PC端点击和移动端触摸操作,该事件能兼容鼠标点击、触摸屏幕等多种交互行为。

修改后的XML代码

<TextBlock Text="Se connecter" 
           VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="50"
           PointerPressed="TextBlock_PointerPressed" />

修改后的C#代码

private void TextBlock_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    MessageBox.Show("test");
}

额外优化建议

  • 确保TextBlock有足够的交互区域:移动端触摸操作建议元素最小尺寸为48x48px,可通过添加Padding属性扩大点击范围,比如:
    <TextBlock Text="Se connecter" 
               VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="50"
               PointerPressed="TextBlock_PointerPressed"
               Padding="10" />
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 21:19:49