有没有办法在xaml中为每一行添加DoubleClickEvent而不是使用datagridcontrol的事件?
像这样的东西(这段代码不起作用):
<UserControl
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" >
<xcdg:UserControl.Resources>
<Style TargetType="xcdg:DataRow">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<cmd:EventToCommand Command="{Binding SelectCommand, Mode=Default}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataGridControl}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Style>
</xcdg:UserControl.Resources>
...
答案 0 :(得分:1)
使用模板而不是样式。 (这假设xceed datagrid的DataRow是可模板化的。)
<UserControl ...>
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate x:Key="DataTemplateKey">
<Grid>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<cmd:EventToCommand Command="{Binding SelectCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!-- put your row template here -->
</Grid>
<CheckBox Content="{Binding Path=ApplianceActionID, Converter={StaticResource LookupConverter}, ConverterParameter=ApplianceActionLookupValues}"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" />
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
<!-- UI -->
</UserControl>