2012-04-26 1 views

答えて

10

スクロールバーA:

DependencyObject dep = (DependencyObject)e.OriginalSource; 

// iteratively traverse the visual tree 
while ((dep != null) && 
     !(dep is DataGridCell) && 
     !(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 
} 

詳細 - マウスのクリックイベント内のヒットポイントの詳細については、ヘッダーはグリッドの一部ですが、ダブルクリックを処理しないため、イベントはグリッドまで「バブル」します。

イベントソースまたはマウス座標の平均値によって「何がクリックされたか」がわかりにくい解決策です。

しかし、あなたはまた、そのようなもの(未テスト)を行うことができます:私は取得するには、これを読んだ

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

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

を助けていただければ幸いです –

関連する問題