gpt4 book ai didi

wpf - 如何在 WPF dataGrid 中的 TAB 键上添加新行

转载 作者:行者123 更新时间:2023-12-02 04:09:46 25 4
gpt4 key购买 nike

当我在数据网格的最后一个单元格上按“TAB”键时,我想在我的数据网格中添加一个新行。

我正在使用 MVVM 模式来执行此操作。我有一个解决方案,我将 Tab 键分配给数据网格的输入绑定(bind):

    <DataGrid.InputBindings>
<KeyBinding Command="{Binding Path=InsertNewLineCommand}" Key="Tab"></KeyBinding>
</DataGrid.InputBindings>

并将以下代码添加到 InsertNewLineCommand:
private void ExecuteInsertNewLineCommand()
{
//Checked is SelectedCell[0] at last cell of the datagrid
{
InsertNewLine();
}
}

但问题在于在网格上添加 KEYBINDING='TAB' 我的正常选项卡功能会禁用(移动到下一个单元格等等...)

最佳答案

只需确定您是否在最后一列,然后执行您的命令。

我正在使用 PreviewKeyDown,所以我可以测试逻辑,但你可以将它放在你的 executeCommand 方法中。无论如何,这应该让你开始:

<DataGrid PreviewKeyDown="DataGrid_PreviewKeyDown" SelectionUnit="Cell" ....

private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (!Keyboard.IsKeyDown(Key.Tab)) return;
var dataGrid = (DataGrid) sender;

var current = dataGrid.Columns.IndexOf(dataGrid.CurrentColumn);
var last = dataGrid.Columns.Count - 1;

if (current == last)
ExecuteInsertNewLineCommand();

}

关于wpf - 如何在 WPF dataGrid 中的 TAB 键上添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5881263/

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