wpf datagrid 行双击事件

Xaml:

<DataGrid ItemsSource="{Binding SessionList}"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
AutoGenerateColumns="False"
ScrollViewer.CanContentScroll="False"
IsReadOnly="True"
HorizontalScrollBarVisibility="Auto"
SelectionMode="Single"
VerticalScrollBarVisibility="Auto"
MouseDoubleClick="datagrid_MouseDoubleClick"
CanUserAddRows="True"/>

cs代码:

private void datagrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
  DataGrid datagrid = sender as DataGrid;
  Point aP = e.GetPosition(datagrid);
  IInputElement obj = datagrid.InputHitTest(aP);
  DependencyObject target = obj as DependencyObject;


  while (target != null)
  {
    if (target is DataGridRow)
    {
      break;
    }
    target = VisualTreeHelper.GetParent(target);
  }
}

posted on 2015-08-06 14:45  明月几时有25  阅读(8006)  评论(0编辑  收藏  举报