gpt4 book ai didi

wpf - 当 DataGrid 接收到键盘焦点时,关注 SelectedItem 的 DataGridCell

转载 作者:行者123 更新时间:2023-12-04 11:54:16 25 4
gpt4 key购买 nike

我有一个 DataGrid SelectedItem绑定(bind)到 VM Selected 属性。我有一个搜索控件,可以进行查找和 SelectedItemDataGrid更改(并滚动到 View 中)。 WPF 4.0 和 DataGrid SelectionUnit="FullRow" .

我的问题是焦点。 DataGrid接收焦点(通过附加属性/绑定(bind)),但您不能使用 Up、Down、Page Up、Page Down 键更改行(SelectedItem)。如果我再次 tab,显示的第一行的第一个单元格被选中,这会改变 SelectedItem .

底线,我怎样才能将键盘焦点赋予 DataGridCell对于SelectedItemDataGrid获得焦点?

有这么多DataGrid/Focus问题并已经尝试了一些事情。谢谢你的帮助。

最佳答案

您需要为新选择的行提供逻辑焦点。选择新项目后,尝试替换您的 SetFocus用这个打电话:

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

关于wpf - 当 DataGrid 接收到键盘焦点时,关注 SelectedItem 的 DataGridCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17117281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com