MvvmLight EventToCommand和WPFToolkit DataGrid中双击 [英] MvvmLight EventToCommand and WPFToolkit DataGrid double-click
问题描述
试图找出如何使用EventToCommand设置的行DataGrid中双击处理程序。该命令居住在视图模型的每一行。刚是的离谱了我的经验,因为我没有用互动呢。
Trying to figure out how to use EventToCommand to set a datagrid double click handler for rows. The command lives in the viewmodel for each row. Just that much out of my experience, since I haven't used interactions yet.
感谢。
我会用mvvmlight标签,但我没有足够高的声望还没有做出新的标签。
I would have used mvvmlight tag, but I don't have high enough rep yet to make new tags.
推荐答案
这将是解决办法,如果命令住在GridVieModel,而不是对RowViewModel。
This would be the solution if the Command lives on the "GridVieModel" and not on the "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>
您可以创建一个rowview自排也有自己的视图模型,并用一个孩子的MouseDoubleClick事件。在rowview行(容器)的元素
You could create a rowview since the row also has its own viewmodel and use the mousedoubleclick event of a child element of the row (container) in the rowview.
或者您为您的命令绑定一个转换器:
Or you create a converter for your command binding:
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding SelectedItem, ElementName=dg, Mode=OneWay, Converter=...}"/>
转换器,然后将检查selectedItem设置为所需类型的返回指令(喜欢的东西ISelectCommandable用RelayCommand属性)
The converter then would check if the selectedItem is of the required type to return the command (Something like ISelectCommandable with a RelayCommand Property)
这篇关于MvvmLight EventToCommand和WPFToolkit DataGrid中双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!