【问题标题】:Wpf DataGrid DoubleClick has weird behaviourWpf DataGrid DoubleClick 有奇怪的行为
【发布时间】:2011-05-17 16:11:58
【问题描述】:
我正在使用 Wpf DataGrid。我已经处理了 DataGrid 的 MouseDoubleClick 事件以在单独的页面中详细打开记录。所以功能应该就像我双击记录一样,它应该在单独的页面中打开。目前,当我双击 DataGrid 标题(列标题)或 ScrollBar 时,它需要双击所选行(所选记录)。如果只双击行,我希望它双击行。请大家帮忙!!
【问题讨论】:
标签:
c#
wpf
xaml
datagrid
double-click
【解决方案1】:
尝试在 DataGrid 中处理 LoadingRow 事件,然后在每一行中处理 DoubleClick 事件:
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.MouseDoubleClick += new MouseButtonEventHandler(Row_MouseDoubleClick);
}
【解决方案2】:
当使用 DataGrid(单击列标题)时,有时会再次触发 LoadingRow 事件。
我必须取消订阅并重新订阅 MouseDoubleClick 才能完成这项工作:
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e) {
e.Row.MouseDoubleClick -= Row_MouseDoubleClick;
e.Row.MouseDoubleClick += Row_MouseDoubleClick;
}