C# WPF:在ItemsControl中按Enter键时从一个单元格移动到下一个单元格

C# WPF:在ItemsControl中按Enter键时从一个单元格移动到下一个单元格,c#,wpf,xaml,data-entry,C#,Wpf,Xaml,Data Entry,我有一个WPF控件,定义如下: <ItemsControl ItemsSource="{Binding DutyValueBinders}" IsEnabled="{Binding Enabled}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation=

我有一个WPF控件,定义如下:

        <ItemsControl ItemsSource="{Binding DutyValueBinders}" IsEnabled="{Binding Enabled}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Value, TargetNullValue=''}"  Width="50"></TextBox>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
<UserControl ...
             (Other references)
             ... 
             d:DesignHeight="300" d:DesignWidth="300" PreviewKeyDown="UserControl_PreviewKeyDown">
并将XAML的标头修改如下:

        <ItemsControl ItemsSource="{Binding DutyValueBinders}" IsEnabled="{Binding Enabled}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Value, TargetNullValue=''}"  Width="50"></TextBox>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
<UserControl ...
             (Other references)
             ... 
             d:DesignHeight="300" d:DesignWidth="300" PreviewKeyDown="UserControl_PreviewKeyDown">

问题是,由于XAML定义中只有一个文本框,因此没有tabindex顺序,因此当您按Enter键时,光标就消失了


除了完全废弃XAML并使用不同类型的控件重新开始之外,还有什么方法可以做到这一点吗?

像这样处理
项控件的
预览向下事件怎么样

<ItemsControl ItemsSource="{Binding DutyValueBinders}" IsEnabled="{Binding Enabled}"
              PreviewKeyDown="ItemsControl_PreviewKeyDown">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Value, TargetNullValue=''}"  Width="50"></TextBox>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

我不明白这个
ItemsControl
怎么会产生多行。