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

不得不改變什麼事情會在屏幕上修改(在我的情況下的位置),但工作完美.....非常感謝 –