Expression Blend onLongClick event
本文关键字:event onLongClick Blend Expression | 更新日期: 2023-09-27 18:16:00
我想用Expression Blend (SketchFlow)做一个非常简单的事情。
我想在屏幕上有一个按钮,当它被按下超过3秒时,它应该转到另一个屏幕。
我想用这个(绿色答案):按键长按
在MouseLeftButtonDown,但我不知道如何改变到另一个屏幕使用c#代码…只需设置"导航到"选项。
如果有人能告诉我如何在一个按钮中设置一个长点击行为,这样它就会改变到一个新的屏幕,那就太好了。
您可以使用一个类似但更简单的类:
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),然后使用eventtrigger设置为LongClick来触发你的导航:
<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>