WPF Datagrid -DataGridTemplateColumn选项卡焦点问题 [英] WPF Datagrid -DataGridTemplateColumn tab focus issue
问题描述
通过处理网格的PrepareCellForEdit事件来摆脱这个问题。这是代码
void HODataGrid_PreparingCellForEdit(object sender,DataGridPreparingCellForEditEventArgs e)
{
UIElement inputElement;
///
/// Texbox是我的模板列中的第一个控件
///
inputElement = HODataGridHelper.GetVisualChild< TextBox>(e.EditingElement);
if(inputElement!= null)
{
Keyboard.Focus(inputElement);
}
}
I am using Microsoft WPF datagrid. I have noticed a strange behavior with WPF datagrid DataGridTemplateColumn. When you use the templateColumn in the grid and the template column contains some controls when you tab from the previous column the focus is not automatically given to the first element declared in the template column. The foucs is initally set on the border of the template column and when we tab of once agin the focus goes to the first column. Any workaround for this issue. How can i set the focus to go the first element in the template column of the datagrid when i tab off.
I got rid of this problem by handling PrepareCellForEdit event of the grid. Here is the code
void HODataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
UIElement inputElement;
///
/// Texbox is the first control in my template column
///
inputElement = HODataGridHelper.GetVisualChild<TextBox>(e.EditingElement);
if (inputElement != null)
{
Keyboard.Focus(inputElement);
}
}
这篇关于WPF Datagrid -DataGridTemplateColumn选项卡焦点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!