我正在尝试处理ViewModel类中的DataGrid事件。由于DataGrid中没有Command属性,因此处理DataGrid中的事件变得非常困难。我提到Interaction.Triggers,但System.Windows.Interactivity.dll在构建项目时给出了一些异常。请帮帮我。
答案 0 :(得分:1)
这是我在项目中所做的一个例子。我使用EventToCommand的mvvm light版本,但System.Windows.Interactivity.dll也应该可以使用
<DataGrid ItemsSource="{Binding MyView}" AutoGenerateColumns="False"
x:Name="myProtokollList"
IsReadOnly="True"
CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="true"
SelectionMode="Extended" SelectionUnit="FullRow"
SelectedItem="{Binding SelectedRow, Mode=OneWay}"
IsSynchronizedWithCurrentItem="true">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<Commanding:EventToCommand Command="{Binding Path=OpenCommand}"
CommandParameter="{Binding ElementName=myProtokollList, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>