首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Expression Blend onLongClick事件

Expression Blend onLongClick事件
EN

Stack Overflow用户
提问于 2011-11-26 10:22:52
回答 1查看 332关注 0票数 0

我想用Expression Blend (SketchFlow)做一件非常简单的事情。

我想在屏幕上有一个按钮,当它被按下超过3秒时,它应该转到另一个屏幕。

我考虑过使用这个(绿色答案):Button Long Click

在MouseLeftButtonDown中,我不知道如何通过设置“导航到”选项来使用c# code...just切换到另一个屏幕。

所以,如果有人能告诉我如何在按钮中设置长点击行为,让它变成一个新的屏幕,那就太好了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-29 00:27:41

下面是一个类似但更简单的类,您可以使用它:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.Windows.Threading;

namespace SilverlightApplication14
{
    public class LongClickButton : Button
    {
        public event EventHandler LongClick;

        public static DependencyProperty HowLongProperty = DependencyProperty.Register("HowLong", typeof(double), typeof(LongClickButton), new PropertyMetadata(3000.0));

        public double HowLong
        {
            get
            {
                return (double)this.GetValue(HowLongProperty);
            }
            set
            {
                this.SetValue(HowLongProperty, value);
            }
        }

        private DispatcherTimer timer;

        public LongClickButton()
        {
            this.timer = new DispatcherTimer();
            this.timer.Tick += new EventHandler(timer_Tick);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.timer.Stop();
            // Timer elapsed while button was down, fire long click event.
            if (this.LongClick != null)
            {
                this.LongClick(this, EventArgs.Empty);
            }
        }

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            this.timer.Interval = TimeSpan.FromMilliseconds(this.HowLong);
            this.timer.Start();
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);
            this.timer.Stop();
        }
    }

}

这样,您就可以将Blend中的任何标准行为与新的LongClick事件一起使用。将HowLong属性设置为所需的毫秒数(默认值为3000),然后使用设置为LongClick的eventtrigger来触发导航:

代码语言:javascript
复制
<local:LongClickButton Margin="296,170,78,91">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="LongClick">
                <ei:ChangePropertyAction PropertyName="Background" TargetName="LayoutRoot">
                    <ei:ChangePropertyAction.Value>
                        <SolidColorBrush Color="#FFFF1C1C"/>
                    </ei:ChangePropertyAction.Value>
                </ei:ChangePropertyAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </local:LongClickButton>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8275836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档