gpt4 book ai didi

c# - 即使在 wpf datagrid 中失去焦点后,单元格仍处于编辑模式

转载 作者:太空狗 更新时间:2023-10-29 19:44:03 27 4
gpt4 key购买 nike

我有一个 DataGrid,其中有两列,即 NameGroup

我使用了 EnterKeyTravarsal 类,因此我可以将 Enter 用作 TAB

另外,根据某些条件,我使用 InputBindings 向 ViewModel 中的 DataGrid 添加了一个新行。

但是当添加新行时,我可以看到在添加新行之前获得焦点的最后一个单元格仍处于编辑模式。

Here是我创建的示例项目,用于清楚地解释我的问题。

最佳答案

更新你的类 EnterKeyTraversal

static void ue_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
var ue = e.OriginalSource as FrameworkElement;
DataGrid dg = FindVisualParent<DataGrid>(ue) as DataGrid;
DataGridCell cell = FindVisualParent<DataGridCell>(ue);

if (e.Key == Key.Enter)
{
//e.Handled = true;

if (dg != null)
{
dg.CommitEdit();
}

if (cell != null)
{
cell.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
else
{
ue.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}

if (dg != null)
{
dg.BeginEdit();
}
}
}

关于c# - 即使在 wpf datagrid 中失去焦点后,单元格仍处于编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23393137/

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