FlipView SelectionChanged 事件仅在触摸操作完成时发生 [英] FlipView SelectionChanged event occurs only when touch manipulations are complete

查看:16
本文介绍了FlipView SelectionChanged 事件仅在触摸操作完成时发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自文档:

注意当用户使用触摸翻阅 FlipView 内容时交互,只有在触摸时才会发生 SelectionChanged 事件操作完成.这意味着当用户翻阅内容很快,个别 SelectionChanged 事件并不总是为每个项目生成,因为操作仍在发生.

Note When a user flips through FlipView content using touch interaction, a SelectionChanged event occurs only when touch manipulations are complete. This means that when a user flips through content quickly, individual SelectionChanged events are not always generated for every item because the manipulation is still occurring.

有没有办法配置 FlipView 控件为每次翻转触发 SelectionChanged ?这种行为使实现分页变得有趣,因为用户如果翻转速度足够快,可以在添加更多项目之前翻转到列表的末尾.

Is there a way to configure the FlipView control to fire SelectionChanged for each flip? This behavior makes implementing paging interesting as the user, if flipping fast enough, can flip to the end of the list before more items can be added.

推荐答案

该问题的一种解决方案是扩展 FlipView 并监控其 ScrollViewer.这是我建议的快速示例.好像对水平翻转视图有效(其他情况没处理过,也没测试太多).

One solution to the problem is to extend the FlipView and monitor its ScrollViewer. Here is a quick sample of what I'm suggesting. Seems to work on horizontal flip view (haven't handled any other cases, and haven't tested too much).

public class FixedFlipView : FlipView {
    public ScrollViewer ScrollViewer {
        get;
        private set;
    }

    protected override void OnApplyTemplate() {
        base.OnApplyTemplate();

        this.ScrollViewer = (ScrollViewer)this.GetTemplateChild("ScrollingHost");
        this.ScrollViewer.ViewChanged += ScrollViewer_ViewChanged;
    }

    void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) {
        var index = (int)this.ScrollViewer.HorizontalOffset - 2;
        if (this.SelectedIndex != index) {
            this.SelectedIndex = index;
        }
    }
}

注意事项:

  1. 您可能希望以不依赖于其名称的不同方式获取 ScrollViewer.就像使用我的回答中的方法这里一>.不过,我想这也很好.

  1. You may want to get the ScrollViewer in a different way that does not depend on its name. Like using the method in my answer here. Although, I'd guess this is fine, too.

为此使用单独的事件可能是一个更好的主意.在上面的代码中,我设置了 SelectedIndex 属性,它引发了 SelectionChanged 事件,但它也很可能也在做其他事情,所以它可能是一个问题在某些情况下.

It may be a better idea to use a separate event for this. In the code above I set the SelectedIndex property, which raises the SelectionChanged event, but it is also very likely to be doing other stuff as well, so it may be a problem in some cases.

这篇关于FlipView SelectionChanged 事件仅在触摸操作完成时发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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