WPF Datagrid -DataGridTemplateColumn tab focus issue

扶醉桌前 提交于 2019-11-28 09:47:14

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);
      }
}

We solved this problem by modifying the style on DataGridCell:

<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
    <Setter Property="IsTabStop" Value="False"/>
amaca

There is a solution using a static class and one change to the Xaml for the control you want focused. "WPF DataGrid: Tabbing from cell to cell does not set focus on control"

I found out a link in WPF datagrid codeplex discussions http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=35540

Thanks to vincent sibal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!