如何在Windows Phonw 8中执行Hold事件? [英] How to perform Hold event in Windows Phonw 8?

查看:124
本文介绍了如何在Windows Phonw 8中执行Hold事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理Windows Phone 8项目中的保持事件.

I'm trying to deal with hold event on my Windows Phone 8 project.

这是我列表的点击事件

    private void lstData_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        Bus selectedItemData = (sender as ListBox).SelectedItem as Bus;
        if (selectedItemData != null)
        {
            var num = selectedItemData.Number;
            var route = selectedItemData.Route;
            NavigationService.Navigate(new Uri(string.Format("/Details.xaml?parameter1=" + num + "&parameter2=" + route), UriKind.Relative));
        }

这是Hold事件

    private void lstData_Hold(object sender, System.Windows.Input.GestureEventArgs e)
    {

        MessageBoxResult m = MessageBox.Show("Would you like to add this bus to favorite list", "Add to Favorite", MessageBoxButton.OKCancel);
        if(m==MessageBoxResult.OK)
        {
            Bus selectedItemData2 = (sender as ListBox).SelectedItem as Bus;
            if (selectedItemData2 != null)
            {
                MessageBox.Show(selectedItemData2.Route);
            }
        }
    }

问题是我调试时Hold事件中的selectedItemData2变为空.我不明白它如何可能适用于轻按事件而不适用于保持事件.请帮帮我!

The problem is that selectedItemData2 in Hold event comes null when I debugged. I can't understand how it is possible that it work for tap event but not for hold event. Please help me!

推荐答案

在触发Hold事件时,未选择您持有的项目.但是,您可以在hold事件中访问持有e.OriginalSource的项目.

When Hold event fired , the item you holded was not selected.But you can access the item which holded e.OriginalSource in your hold event.

这篇关于如何在Windows Phonw 8中执行Hold事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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