保持事件执行时不应触发单击事件 [英] Click Event should not trigger when hold event perform

查看:35
本文介绍了保持事件执行时不应触发单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows Phone silverlight 8.1 应用程序中有按钮我创建了两个事件,一个点击事件和第二个保持事件,我希望当用户按住这样的按钮时,点击事件不应该触发,但是目前当我按住按钮然后离开该按钮时,单击按钮也会触发,那么如何处理.

i have button in my windows phone silverlight 8.1 app i created two event one click event and second hold event, i want when user hold such button then click event should not fire, but currently when i hold button and then leave that button click button also fires, so how to handle that.

 private void ExtraButton_Click(object sender, RoutedEventArgs e)
 {

 }

 private void ExtraButton_Hold(object sender, GestureEventArgs e)
 {

 }

那么如何在执行保持事件时取消点击事件.

so how to cancel click event when hold event performed.

推荐答案

我建议你可以将 Button Click 事件替换为 Button Tap 事件,因为当你按住这个按钮,按钮保持事件将首先被触发.

I suggest you can replace the Button Click event with Button Tap event, because when you hold this button, the Button Hold event will be triggered firstly.

        private void button1_Hold(object sender, System.Windows.Input.GestureEventArgs e)
    {
        e.Handled = true;  
        MessageBox.Show("button have been holded");

    }

    private void button1_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        MessageBox.Show("button have been tapped");
        //your code goes here
    }

将 Handled 属性设置为 true 后,Button Click 事件将不会处理您的手势.

After you set Handled property as true, then the Button Click event will not handle your gesture.

这篇关于保持事件执行时不应触发单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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