Expand the WPF DataGrid and press the arrow key to move the focus.
The default moving behavior of the WPF DataGrid is as follows:
(1) When the current cell is not in the editing status, you can use the direction key to move the focus.
(2) When the current cell is in the editing status, you cannot use the direction keys to move the focus;
Press Enter to exit the editing status of the current cell. The focus moves down to a grid;
Press Ctrl + Enter to exit the editing status of the current cell, and move the focus to the upper limit;
Press the Tab key to exit the editing status of the current cell. The focus moves one cell to the right and enters the editing status;
Press Shift + Tab to exit the editing status of the current cell, move the focus to the left, and enter the editing status;
"Operation Management 3.0" users generally have low computer operation levels. Office is the most and most intelligent software they operate on. They believe that all software must be operated in the same way as Office, otherwise, negative reviews will be given, so they require "Operation Management" to be operated in the same way as Excel.
To implement the same way of moving the WPF DataGrid as Excel, You need to override the OnPreviewKeyDown event of the DataGrid:
Public class ExDataGrid: DataGrid {protected override void OnPreviewKeyDown (KeyEventArgs e) {if (e. key = Key. left | e. key = Key. right | e. key = Key. up | e. key = Key. down) {try {base. commitEdit ();} catch (Exception ex) {base. cancelEdit (); string mess = ex. message; if (ex. innerException! = Null) mess + = "nn" + ex. InnerException. Message; MessageBox. Show (mess) ;}} base. OnPreviewKeyDown (e );}}View Code
Replace the DataGrid with the overwritten ExDataGrid.
Reprinted from: http://www.yuzifu.net/index.php/2010/11/%E6%89%A9%E5%B1%95wpf%E7%9A%84datag