MvvmLight EventToCommand和WPFToolkit DataGrid双击

试图弄清楚如何使用EventToCommand为行设置datagrid双击处理程序。 该命令位于每行的viewmodel中。 我的经验就是这么多,因为我还没有使用过互动。

谢谢。

我会使用mvvmlight标签,但我还没有足够高的代表来制作新标签。

如果Command位于“GridVieModel”而不是“RowViewModel”上,这将是解决方案。

         

您可以创建一个rowview,因为该行也有自己的viewmodel,并使用rowview中行(容器)的子元素的mousedoubleclick事件。

或者您为命令绑定创建转换器:

  

然后转换器将检查selectedItem是否是返回命令所需的类型(类似于使用RelayCommand属性的ISelectCommandable)

万一有人来这里看,并想知道我是如何用EventToCommand完成它的

 public class DataGridAttachedBehaviors { #region DoubleClick public static DependencyProperty OnDoubleClickProperty = DependencyProperty.RegisterAttached( "OnDoubleClick", typeof(ICommand), typeof(DataGridAttachedBehaviors), new UIPropertyMetadata(DataGridAttachedBehaviors.OnDoubleClick)); public static void SetOnDoubleClick(DependencyObject target, ICommand value) { target.SetValue(DataGridAttachedBehaviors.OnDoubleClickProperty, value); } private static void OnDoubleClick(DependencyObject target, DependencyPropertyChangedEventArgs e) { var element = target as Control; if (element == null) { throw new InvalidOperationException("This behavior can be attached to a Control item only."); } if ((e.NewValue != null) && (e.OldValue == null)) { element.MouseDoubleClick += MouseDoubleClick; } else if ((e.NewValue == null) && (e.OldValue != null)) { element.MouseDoubleClick -= MouseDoubleClick; } } private static void MouseDoubleClick(object sender, MouseButtonEventArgs e) { UIElement element = (UIElement)sender; ICommand command = (ICommand)element.GetValue(DataGridAttachedBehaviors.OnDoubleClickProperty); command.Execute(null); } #endregion DoubleClick #region SelectionChanged //removed #endregion } 

在我的xaml中: