wpf datagrid 双击事件
时间: 2023-08-01 07:15:04 浏览: 187
在WPF中,可以通过使用命令和交互行为来实现DataGrid的双击事件。首先,在XAML文件中导入命名空间`xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"`。然后,在DataGrid下面添加以下代码:
```xml
<DataGrid ItemsSource="{Binding DeviceInfos}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding Path=DoubleClickItem}" CommandParameter="{Binding ElementName=da1,Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
```
这段代码将DataGrid的`MouseDoubleClick`事件与一个命令`DoubleClickItem`绑定起来。当双击DataGrid中的某一项时,命令将被执行,并将选中的项作为参数传递给命令。这样就实现了DataGrid的双击事件。\[2\]\[3\]
#### 引用[.reference_title]
- *1* [wpf datagrid 行双击事件](https://blog.csdn.net/dieruowan6112/article/details/101202876)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [WPF datagrid双击事件获取双击的对象或值MVVM](https://blog.csdn.net/weixin_38083655/article/details/109187564)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文