출처 : http://dotnet-experience.blogspot.kr/2011/01/wpf-datagrid-row-double-click.html

 

DataGrid에 마우스 더블 클릭 이벤트를 주고 해당 아이템의 Row 행을 찾는 소스 입니다.

 

 

[XAML 파일]

<DataGrid x:Name="dataGrid" MouseDoubleClick="DataGrid_MouseDoubleClick"/>

 

[CS 파일]

private void DataGrid_MouseDoubleClick(object sender,
                                  System.Windows.Input.MouseButtonEventArgs e)
{
    IInputElement element = e.MouseDevice.DirectlyOver;
    if(element != null && element is FrameworkElement)
    {
        if (((FrameworkElement)element).Parent is DataGridCell)
        {
            var grid = sender as DataGrid;
            if (grid != null && grid.SelectedItems != null
&& grid.SelectedItems.Count == 1)
            {
                var rowView = grid.SelectedItem as DataRowView;
                if (rowView != null)
                {
                    DataRow row = rowView.Row;
                    //do something with the underlying data
                }
            }
        }
    }
}

 

 

 

 

 

 

+ Recent posts