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

Xamarin Forms中SwipeView滑动触发Invoked事件的偏移量是多少

Xamarin.Forms SwipeView Execute模式触发偏移说明

当SwipeItems的Mode设置为Execute时,SwipeView的Invoked事件触发偏移为你设置的Threshold属性值的60%,这个是Xamarin.Forms框架内置的固定比例。你实测的Threshold设为80时触发偏移在49~50区间,和80*0.6=48的计算结果基本一致,差异来源于滑动偏移计算时的像素浮点值舍入。

该60%的触发比例是写在各平台SwipeView渲染器的内部逻辑中,目前官方没有公开可直接访问的属性或方法来获取该比例值,也不支持通过公开API修改该比例。

如果你需要自行匹配或调整触发逻辑,可采用以下方案:

  • 通过SwipeChanging事件的参数获取实时滑动偏移量,结合Threshold * 0.6的逻辑自行计算触发点,和官方内置触发逻辑保持对齐
  • 如果需要自定义触发比例,可通过自定义SwipeView渲染器,重写对应平台的滑动判定逻辑,调整触发阈值的计算规则

你给出的示例代码格式化后如下:

<SwipeView
    SwipeChanging="SwipeView_SwipeChanging"
    SwipeEnded="SwipeView_SwipeEnded"
    SwipeStarted="SwipeView_SwipeStarted"
    Threshold="80">
    <SwipeView.TopItems>
        <SwipeItems Mode="Execute" SwipeBehaviorOnInvoked="Close">
            <SwipeItemView BackgroundColor="Transparent" Invoked="SwipeItemView_Invoked">
                <Label Text="Create New Task" />
            </SwipeItemView>
        </SwipeItems>
    </SwipeView.TopItems>
    <SwipeView.Content>
    ...
    </SwipeView.Content>
</SwipeView>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 12:36:03