wpf datagrid 行双击事件

https://docs.devexpress.com/WPF/7875/index

Xaml:

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);
  }
}





转载于:https://www.cnblogs.com/robertyao/p/10076320.html

你可能感兴趣的:(wpf datagrid 行双击事件)