1. 程式人生 > >WPF DataGrid 滑鼠雙擊 選中的 DataGridRow 及 行對應資料

WPF DataGrid 滑鼠雙擊 選中的 DataGridRow 及 行對應資料

    Point aP = e.GetPosition(this.dgUsers);
            IInputElement obj = this.dgUsers.InputHitTest(aP);
            System.Windows.DependencyObject target = obj  as System.Windows.DependencyObject;


            while (target != null)
            {
                if (target is Microsoft.Windows.Controls.DataGridRow)
                {
                    Microsoft.Windows.Controls.DataGridRow aDGR = target as Microsoft.Windows.Controls.DataGridRow;
                    DataRowView theDRV = aDGR.Item as DataRowView;
                    SelectedRow = theDRV.Row;
                    break;
                }


                target = VisualTreeHelper.GetParent(target);

            }

///SelectedRow  為返回行