【问题标题】:Scrolling the Datagrid firing mouse double click event滚动 Datagrid 触发鼠标双击事件
【发布时间】:2013-08-29 09:41:07
【问题描述】:

我有一个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>

【问题讨论】:

标签: wpf xaml datagrid eventtrigger


【解决方案1】:

我只能假设您的Interaction.Triggers 导致了您的问题。我接受您想将该事件“转换”为Command,但如果您改为(只是暂时)实现标准MouseDoubleClick 处理程序,您将看到滚动不会触发处理程序完全没有。

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

【讨论】:

  • 这是不正确的。这是相同的行为,因为双击处理程序是针对整个数据网格的。
猜你喜欢
  • 2019-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
  • 2012-11-26
  • 1970-01-01
相关资源
最近更新 更多