2012-12-06 49 views

回答

1

您需要爲此使用Blend,並使用交互觸發器做類似的事情。在你的命令參數,當執行委託打響了鼠標的EventArgs將出席..

<Button> 
<i:Interaction.Triggers> 
    <i:EventTrigger EventName="MouseDoubleClick" > 
     <cmd:EventToCommand Command="{Binding MouseDoubleClickCommand}" 
      PassEventArgsToCommand="True" /> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

如果您不能使用交互的dll試試這個..

public static class MouseDoubleClickBehavior 
{ 
    /// <summary> 
    /// Hooks up a weak event against the source Selectors MouseDoubleClick 
    /// if the Selector has asked for the HandleDoubleClick to be handled 
    ///� 
    /// If the source Selector has expressed an interest in not having its 
    /// MouseDoubleClick handled the internal reference 
    /// </summary> 
    private static void OnHandleDoubleClickCommandChanged(DependencyObject d, 
     DependencyPropertyChangedEventArgs e) 
    { 
     FrameworkElement ele = d as FrameworkElement; 
     if (ele != null) 
     { 
      ele.MouseLeftButtonDown -= OnMouseDoubleClick; 
      if (e.NewValue != null) 
      { 
       ele.MouseLeftButtonDown += OnMouseDoubleClick; 
      } 
     } 
    } 

    /// <summary> 
    /// TheCommandToRun : The actual ICommand to run 
    /// </summary> 
    public static readonly DependencyProperty DoubleClickCommandProperty = 
     DependencyProperty.RegisterAttached("DoubleClickCommand", 
      typeof(ICommand), 
      typeof(MouseDoubleClickBehavior), 
      new FrameworkPropertyMetadata((ICommand)null, 
       new PropertyChangedCallback(OnHandleDoubleClickCommandChanged))); 

    /// <summary> 
    /// Gets the TheCommandToRun property. � 
    /// </summary> 
    public static ICommand GetDoubleClickCommand(DependencyObject d) 
    { 
     return (ICommand)d.GetValue(DoubleClickCommandProperty); 
    } 

    /// <summary> 
    /// Sets the TheCommandToRun property. � 
    /// </summary> 
    public static void SetDoubleClickCommand(DependencyObject d, ICommand value) 
    { 
     d.SetValue(DoubleClickCommandProperty, value); 
    } 

    #region Handle the event 

    /// <summary> 
    /// Invoke the command we tagged. 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    private static void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) 
    { 
     //check for double clicks. 
     if (e.ClickCount != 2) 
      return; 
     FrameworkElement ele = sender as FrameworkElement; 

     DependencyObject originalSender = e.OriginalSource as DependencyObject; 
     if (ele == null || originalSender == null) 
      return; 

     ICommand command = (ICommand)(sender as DependencyObject).GetValue(DoubleClickCommandProperty); 

     if (command != null) 
     { 
      if (command.CanExecute(null)) 
       command.Execute(null); 
     } 
    } 
    #endregion 
} 

和綁定使用此 - MouseDoubleClickBehavior.DoubleClickCommand =「{Binding SomeCommand}」

+0

我知道這種方式,但我沒有System.Windows.Interactivity.dll,我不允許在我的項目中添加新的.dlls,所以我不能使用它。我試着用AttachedCommandBehaviour來做。但我認爲這是不可能的。 – Athina

+0

請參閱編輯..對於行爲... –