且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c#,UI自动化:双击WPF datagrid行

更新时间:2023-02-08 21:16:55

一旦您引用了DataGrid及其DataGridRow元素,就可以以编程方式双击一行通过引发MouseDoubleClick事件:

Once you have a reference to the DataGrid and one its DataGridRow elements, you could programmatically double click a row by raising a MouseDoubleClick event:

DataGrid dataGrid = nameOfYourGrid;
DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromIndex(0) as DataGridRow; //first row

MouseButtonEventArgs args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left) { RoutedEvent = Control.MouseDoubleClickEvent };
row.RaiseEvent(args);