在 ListView 中滑动的问题 [英] Issue with Swipe inside ListView

查看:27
本文介绍了在 ListView 中滑动的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 应用商店应用中使用 ListView.每当我开始在列表视图上滑动(使用模拟器点击模式)时,所有项目都会一起移动,如图所示.如何禁用此操作事件?

I am using a ListView in a Windows Store App. Whenever I start swiping(using simulator tap mode) over the list view all the items move together as illustrated in the picture. How can I disable this manipulation event?

推荐答案

在你的 ListView 中,添加:

ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollMode="Disabled"

如果这还不够(这有时不适用于 MouseWheel 事件,因为这些事件仍然倾向于在 ListView 中捕获,并且如果 ScrollViewer 内部的列表特别大,也倾向于发生,我发现),那么你需要创建一个自定义控件来专门忽略该事件,例如对于PointerWheelChanged.

If that is not enough (this sometimes does not work with MouseWheel events, in that the events still tend to be caught in the ListView and also tends to happen if the list inside of the ScrollViewer is particularly large, I've found), then you need to create a custom control to specifically ignore the event, such as this for PointerWheelChanged.

public class CustomListView : ListView
{
    protected override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var sv = this.GetTemplateChild("ScrollViewer") as UIElement;
        if (sv != null)
            sv.AddHandler(UIElement.PointerWheelChangedEvent, new PointerEventHandler(OnPointerWheelChanged), true);
    }

    private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
    {
        e.Handled = false;
    }
}

这将禁用 ListView 内的鼠标滚轮滚动.您必须将您对 ListView 的 XAML 引用从 更改为 其中 namespace 是您在其中创建 ListView 的命名空间.

This will disable mouse wheel scrolling inside of your ListView. You'll have to change your XAML reference to the ListView from <ListView> to <namespace:ListView> where namespace is the namespace you've created your ListView in.

这篇关于在 ListView 中滑动的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆