滚动Datagrid触发鼠标双击事件

时间:2013-08-29 09:41:08

标签: wpf xaml datagrid eventtrigger

我有DataGrid并且我想在双击行时显示另一个表单,但即使我正在滚动数据网格,此事件也会触发。如何在双击行时才启动它?

我正在使用MVVM模式。

<DataGrid Name="dgScopeRecords" Grid.Row="1" Grid.ColumnSpan="3" IsReadOnly="True" ItemsSource="{Binding Model.TableScopeRecords}" SelectedIndex="{Binding Model.SelectedIndex}" Margin="0,10,0,0" AutoGenerateColumns="False" SelectionMode="Single">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <i:InvokeCommandAction Command="{Binding ViewScopeRecordCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <DataGrid.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#dca188"/>
    </DataGrid.Resources>

    <DataGrid.Columns>
        <DataGridTextColumn Header="{x:Static Resources:Translations.RecordsInspection_ColumnScope}" Binding="{Binding Scope.ScopeName}" Width="250"/>
        <DataGridTextColumn Header="{x:Static Resources:Translations.RecordsInspection_ColumnScopeType}" Binding="{Binding Scope.ScopeType.ScopeTypeName}" Width="100"/>
    </DataGrid.Columns>
</DataGrid>

1 个答案:

答案 0 :(得分:0)

我只能假设您Interaction.Triggers导致了您的问题。我接受您要将该事件“转换”为Command,但如果您实现标准MouseDoubleClick处理程序(暂时),您会看到滚动根本解雇处理程序。

您仍然可以将自己的自定义Command中的该事件转换为Attached Property。它们创建起来相对简单,您可以从MSDN的Attached Properties Overview页面了解如何执行此操作。

相关问题