Focus on DataGridCell for SelectedItem when DataGrid Receives Keyboard Focus

后端 未结 3 1233
南笙
南笙 2020-12-30 11:19

I have a DataGrid where the SelectedItem is bound to a VM Selected property. I have a search control that will do a find and the SelectedItem

3条回答
  •  一生所求
    2020-12-30 11:50

    You need to give the newly selected row logical focus. After selecting the new item try replacing your SetFocus call with this:

            var selectedRow = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(dataGrid1.SelectedIndex);
            FocusManager.SetIsFocusScope(selectedRow, true);
            FocusManager.SetFocusedElement(selectedRow, selectedRow);
    

提交回复
热议问题