作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我在数据网格的最后一个单元格上按“TAB”键时,我想在我的数据网格中添加一个新行。
我正在使用 MVVM 模式来执行此操作。我有一个解决方案,我将 Tab 键分配给数据网格的输入绑定(bind):
<DataGrid.InputBindings>
<KeyBinding Command="{Binding Path=InsertNewLineCommand}" Key="Tab"></KeyBinding>
</DataGrid.InputBindings>
private void ExecuteInsertNewLineCommand()
{
//Checked is SelectedCell[0] at last cell of the datagrid
{
InsertNewLine();
}
}
最佳答案
只需确定您是否在最后一列,然后执行您的命令。
我正在使用 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/
我是一名优秀的程序员,十分优秀!