【问题标题】:Handling PointerReleased events in Flipview在 Flipview 中处理 PointerReleased 事件
【发布时间】:2013-11-14 08:14:49
【问题描述】:

我正在尝试创建一个应用程序,其中包含一个翻转视图,当用户有一段时间没有与之交互时,它会自动翻转到下一页。使用基本的 DispatcherTimer 可以正常工作,当翻转视图的选择更改时会重新启动。

到目前为止一切顺利,但我也不希望计时器在用户与翻转视图中的当前项目交互时运行,例如列表视图或其他东西。我想我可以将 PointerPressed 和 PointerReleased 处理程序连接到页面,并在按下指针时停止计时器,并在释放指针时重新启动它。

这有效,除非指针位于翻转视图上:按下的处理程序被执行,但 FlipView 吞噬了所有其他指针事件,因此 PointerReleased 处理程序永远不会被执行。

我不知道如何让它工作。在 WPF 中,我只使用隧道事件,但整个概念似乎随着 WinRT 消失了?关于如何让它发挥作用的任何建议?

使用代码更新

当然。我有一个包含翻转视图和调度程序计时器的页面:

public sealed partial class MainPage : Page
{
    private DispatcherTimer slideScrollTimer;

    public MainPage()
    {
        // Set up a timer that'll flip to the next page every 5 seconds.
        this.slideScrollTimer= new DispatcherTimer()
        {
            Interval = TimeSpan.FromSeconds(5)
        };

        slideScrollTimer.Tick += slideScrollTimer_Tick;
        slideScrollTimer.Start();
    }

    void slideScrollTimer_Tick(object sender, object e)
    {
        // When the timer runs out, go to the next page, or back
        // to the first.
        if (flipView.SelectedIndex < flipView.Items.Count - 1)
        {
            flipView.SelectedIndex++;
        }
        else
        {
            flipView.SelectedIndex = 0;
        }
    }

    private void flipView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // restart the timer if someone flips to a different page
        if (this.slideScrollTimer != null)
        {
            this.slideScrollTimer.Start();
        }
    }
}

基本上我想要的是每当有人触摸应用程序时重置计时器。我尝试使用 AddHandler 添加一个 PointerPressed/PointerReleased 处理程序,但如果您不在翻转视图上,或者只是点击它而不是滚动它或操作其内容,则释放只会触发。

【问题讨论】:

    标签: c# windows-runtime windows-store-apps winrt-xaml


    【解决方案1】:

    您可以使用UIElement.AddHandler 处理已在其他地方标记为已处理的事件。

    为指定的路由事件添加路由事件处理程序,将处理程序添加到当前元素的处理程序集合中。将 handledEventsToo 指定为 true 以调用提供的处理程序,即使该事件在其他地方处理。

    【讨论】:

    • 只有在你点击时才会触发 PointerReleased 事件。如果您触摸、移动和释放,它仍然不会触发。
    • 我在我目前正在进行的项目中遇到了类似的问题,但为了更好地了解解决方案,我必须查看您的一些代码。
    • 关于这种情况的任何更新?我在 windows phone 8.1 中遇到了这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 2014-09-29
    相关资源
    最近更新 更多