试图找出如何使用 EventToCommand 为行设置数据网格双击处理程序。该命令位于每一行的 View 模型中。只是我的经验,因为我还没有使用过交互。
谢谢。
我会使用 mvvmlight 标签,但我还没有足够高的代表来制作新标签。
最佳答案
如果命令位于“GridVieModel”而不是“RowViewModel”,这将是解决方案。
<Window...
...xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras">
<dg:DataGrid x:Name="dg">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<GalaSoft_MvvmLight_Command:EventToCommand CommandParameter="{Binding SelectedItem, ElementName=dg}" Command="{Binding Path=SelectCommand, Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</dg:DataGrid>
</Window>
您可以创建行 View ,因为行也有自己的 View 模型,并在行 View 中使用行(容器)的子元素的 mousedoubleclick 事件。
或者您为您的命令绑定(bind)创建一个转换器:
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding SelectedItem, ElementName=dg, Mode=OneWay, Converter=...}"/>
然后转换器将检查 selectedItem 是否属于返回命令所需的类型(类似于具有 RelayCommand 属性的 ISelectCommandable)
关于c# - MvvmLight EventToCommand 和 WPFToolkit DataGrid 双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1878362/