2012-04-26 66 views

回答

10

一个滚动条nd标题是网格的一部分,但不处理双击,所以事件会“起泡”到网格。

这个不雅的解决方案是通过事件源或鼠标坐标的平均值稍微发现“被点击的东西”。

但你也可以做这样的事情(未经测试):

<DataGrid> 
    <DataGrid.RowStyle> 
    <Style TargetType="{x:Type DataGridRow}"> 
     <EventSetter Event="MouseDoubleClick" Handler="OnRowDoubleClicked"/> 
    </Style> 
    </DataGrid.RowStyle> 
</DataGrid> 
+0

非常感谢它工作得很好 – 2012-04-26 09:46:55

1

您可以检查关于打击点的详细信息,鼠标点击事件中 -

DependencyObject dep = (DependencyObject)e.OriginalSource; 

// iteratively traverse the visual tree 
while ((dep != null) &amp;&amp; 
     !(dep is DataGridCell) &amp;&amp; 
     !(dep is DataGridColumnHeader)) 
{ 
    dep = VisualTreeHelper.GetParent(dep); 
} 

if (dep == null) 
    return; 

if (dep is DataGridColumnHeader) 
{ 
    DataGridColumnHeader columnHeader = dep as DataGridColumnHeader; 
    // do something 
} 

if (dep is DataGridCell) 
{ 
    DataGridCell cell = dep as DataGridCell; 
    // do something 
} 

更多信息: http://www.scottlogic.co.uk/blog/colin/2008/12/wpf-datagrid-detecting-clicked-cell-and-row/

0

我与此有同样的问题,并解决它:

DependencyObject src = VisualTreeHelper.GetParent((DependencyObject)e.OriginalSource); 
if (!(src is Control) && src.GetType() != typeof(System.Windows.Controls.Primitives.Thumb)) 
{ 
    //your code 
} 

我读过这让这个想法:How to detect double click on list view scroll bar?

我希望这会帮助:)

相关问题