Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF DataGrid,文本框在按下向下箭头键时无法获得焦点_C#_Wpf_Datagrid_Textbox - Fatal编程技术网

C# WPF DataGrid,文本框在按下向下箭头键时无法获得焦点

C# WPF DataGrid,文本框在按下向下箭头键时无法获得焦点,c#,wpf,datagrid,textbox,C#,Wpf,Datagrid,Textbox,我在单元格中放置了一些文本框 我真正需要的是,当我按下向下箭头或向上箭头键时,下一行中的下一个文本框或控件应该能够聚焦 <owpfc:FFDataGrid ItemsSource="{Binding Path=Ss}" AutoGenerateColumns="False" SelectionUnit="FullRow"> <i:Interaction.Triggers> <i:EventTri

我在单元格中放置了一些文本框 我真正需要的是,当我按下向下箭头或向上箭头键时,下一行中的下一个文本框或控件应该能够聚焦

        <owpfc:FFDataGrid ItemsSource="{Binding Path=Ss}" AutoGenerateColumns="False" SelectionUnit="FullRow">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewKeyDown">
                    <mvvmlightextra:EventToCommand Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl, AncestorLevel=1}, Path=DataContext.CmdDownKeyDown}" PassEventArgsToCommand="True" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <wpftk:DataGrid.Columns>
                <wpftk:DataGridTemplateColumn Header="Name" IsReadOnly="False">
                    <wpftk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=Ts1}" x:Name="txtName" />
                        </DataTemplate>
                    </wpftk:DataGridTemplateColumn.CellTemplate>

                </wpftk:DataGridTemplateColumn>
                <wpftk:DataGridTextColumn Binding="{Binding Path=Ts2}" Header="Ts2" IsReadOnly="False"/>
            </wpftk:DataGrid.Columns>
        </owpfc:FFDataGrid>

之后我试着

protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e)
    {



        if (e.Key == System.Windows.Input.Key.Down)
        {
            if (SelectedIndex < Items.Count)
            {
                SelectedIndex++;
                DataGridCell cell = GetCell(SelectedIndex, 0);
                var currentFirstControl = (FrameworkElement)cell.Content;
                currentFirstControl.Focus();
            }


        }
        else if (e.Key == System.Windows.Input.Key.Up)
        {
            if (SelectedIndex > 0)
            {
                SelectedIndex--;
                DataGridCell cell = GetCell(SelectedIndex, 1);
                var currentFirstControl = (FrameworkElement) cell.Content;
                currentFirstControl.Focus();
            }


        }

        base.OnPreviewKeyDown(e);
    }
受保护的覆盖void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e)
{
if(e.Key==System.Windows.Input.Key.Down)
{
if(SelectedIndex0)
{
选择索引--;
DataGridCell=GetCell(SelectedIndex,1);
var currentFirstControl=(FrameworkElement)cell.Content;
currentFirstControl.Focus();
}
}
基于预览的向下(e);
}
真的需要你的帮助,谢谢