WPF TabIndex无法正常工作

时间:2015-03-27 13:05:28

标签: c# wpf stackpanel tabindex groupbox

我在设置TabIndexes时遇到问题。我有Usercontrol GroupBox

<GroupBox KeyboardNavigation.TabNavigation="Local" TabIndex="0">
        <Grid KeyboardNavigation.TabNavigation="Continue">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Grid.Row="0" KeyboardNavigation.TabNavigation="Continue">
                <my:uscZeitraum TabIndex="1" />
                <Label />
                <ComboBox TabIndex="2" />
                <Label />
                <ComboBox TabIndex="3" HorizontalAlignment="Right" VerticalAlignment="Top" Width="88" />
                <Label />
                <ComboBox TabIndex="4" HorizontalAlignment="Right" VerticalAlignment="Top" Width="67" />
                <Label />
                <ComboBox TabIndex="5" IsEditable="True" GotFocus="cboVorgang_GotFocus" HorizontalAlignment="Right" VerticalAlignment="Top" Width="93" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="1" KeyboardNavigation.TabNavigation="Continue">
                <Label />
                <ComboBox TabIndex="6" HorizontalAlignment="Left" Width="192" Height="23" VerticalAlignment="Bottom" />
                <Label />
                <ComboBox TabIndex="7" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="225" />
                <Label />
                <ComboBox IsEditable="True" TabIndex="8" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="67" />
                <Label />
                <ComboBox IsEditable="True" TabIndex="9" Width="80" />                                 
            </StackPanel>
        </Grid>
    </GroupBox>

第一个Control也是UserControl,但这样就像我想要的那样。但如果我在第一个ComboBox中达到第三个StackPanel,它就会再次从头开始。它不会聚焦第四个ComboBox,也不会跳转到第二个Row / Stackpanel。那可能是什么?

1 个答案:

答案 0 :(得分:0)

cboVorgang_GotFocus中必须有一些代码正在执行此操作。在那里写的代码将改变标签顺序。