0

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

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

我想过用这个(绿色接听): Button Long Click

中的MouseLeftButtonDown内,但我不知道如何使用C#代码来切换到另一个画面...只是通过设置“导航到”选项。

所以,如果任何人都可以告诉我如何设置一个按钮的长按行为,所以它变成一个新的屏幕,这将是伟大的。

回答

1

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

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> 
+0

的响应非常感谢......我一直在努力执行它...当我可以我会检查它..或者如果我不能我会抱怨:D –

+0

不得不改变什么事情会在屏幕上修改(在我的情况下的位置),但工作完美.....非常感谢 –