WPF datagrid选择行点击事件? [英] WPF datagrid selected row clicked event ?
本文介绍了WPF datagrid选择行点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当双击WPF DataGrid的选定行时,我想执行一些代码。我知道datagrid有一个MouseDoubleClicked事件,它也有一个行选择的事件,但我没有看到任何选定的行双击的事件...
I want to execute some code when a a selected row of the WPF DataGrid is double clicked. I know that the datagrid has a MouseDoubleClicked event and that it also has a row selected event but I don't see any event for "selected row double clicked" ...
你认为有可能以某种方式捕捉这个事件吗?
Do you think it's possible to capture this event somehow ?
推荐答案
您可以在 ItemContainerStyle
中添加事件处理程序应用于一行的样式):
you can add the event handler in the ItemContainerStyle
(which is the style applied to a row) :
<DataGrid ... >
<DataGrid.ItemContainerStyle>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
</Style>
</DataGrid.ItemContainerStyle>
...
</DataGrid>
然后,在处理程序中,您可以检查行是否已选择
Then, in the handler, you can check if the row is selected
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
// execute some code
}
这篇关于WPF datagrid选择行点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文