2012-04-26 64 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?

我希望這會幫助:)

相關問題