开发者

WPF XAML DataGrid : How to add PreviewKeyUp event to all cells?

开发者 https://www.devze.com 2023-02-10 07:10 出处:网络
How to add PreviewKeyUp event to all cells ? I wanna catch tab key press for 开发者_C百科each cell in edit mode.

How to add PreviewKeyUp event to all cells ?

I wanna catch tab key press for 开发者_C百科each cell in edit mode.

Thanks guys


Just register PreviewKeyUp in one of the parent elements such as the DataGrid itself or the window, the Datagrid is within. Analye then the events OriginalSource to know from where the event has been coming.

To access the rows data you can do something like:

FrameworkElement fe=e.OriginalSource;
if(null != fe){
   YourRowDataObject rowData=fe.DataContext as YourRowDataObject;
   // work here with your data
}
0

精彩评论

暂无评论...
验证码 换一张
取 消