2010-01-22 14 views
0

Je veux que l'onglet avance dans chaque élément d'affilée, et ce pour chaque ligne. Mais en réalité, il passe par tous les éléments d'une colonne, colonne après colonne!Comment puis-je obtenir un ordre de tabulation de ligne dans un ItemsControl avec un datatemplate?

Dans le DataTemplate sont 2 Comboboxes (disons cb1 et cb1) et un TextBox (tb). L'onglet réelle commande est la suivante:

Row0.cb1, Row1.cb1 ... Row0.cb2, Row1.cb2 ... Row0.tb, Row1.tb ...

Mais ce que je veux est:

Row0.cb1, Row0.cb2, Row0.tb, Row1.cb1, Row1.cb2, Row1.tb ...

      <ItemsControl ItemsSource="{Binding}" Name="myItemsControl"> 
           <ItemsControl.ItemTemplate> 
            <DataTemplate> 
             <Grid> 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="3*"/> 
               <ColumnDefinition Width="*"/> 
               <ColumnDefinition Width="Auto"/> 
              </Grid.ColumnDefinitions> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="Auto"/> 
              </Grid.RowDefinitions> 
              <ComboBox Grid.Column="0" ItemsSource="{Binding Source={StaticResource SomeItems}}" IsSynchronizedWithCurrentItem="False" SelectedItem="{Binding Path=SomeValue, Mode=TwoWay}" DisplayMemberPath="Name" TabIndex="20"/> 
              <ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource SomeOtherItems}}" IsSynchronizedWithCurrentItem="False" SelectedItem="{Binding Path=SomeOtherValue, Mode=TwoWay}" DisplayMemberPath="Value" TabIndex="21"/> 
              <TextBox HorizontalContentAlignment="Stretch" Grid.Column="2" TabIndex="22" LostKeyboardFocus="TextBox_FormatAfterLostFocus"> 
               <TextBox.Text> 
                <Binding Path="Wert" Mode="TwoWay" /> 
               </TextBox.Text> 
              </TextBox> 
             </Grid> 
            </DataTemplate> 
           </ItemsControl.ItemTemplate> 
          </ItemsControl> 
+0

Pourriez-vous s'il vous plaît partager une image de ce que vous essayez de faire pour nous aider à comprendre votre problème? – japf

+0

Discussion déplacée à: http://stackoverflow.com/questions/2116802/wpf-tabstop-tabindex-in-itemscontrol – nilnitzer

Répondre

-1

Vous avez défini des valeurs TabIndex dans ItemsControl. Ce que WPF fait est de donner à chaque rangée les mêmes TabIndices cela signifie:

row1.cb1.TabIndex = 20 | row1.cb2.TabIndex = 21 | row1.tb.TabIndex = 22
row2.cb1.TabIndex = 20 | row2.cb2.TabIndex = 21 | row2.tb.TabIndex = 22

comme le 20 de la deuxième rangée est inférieur à 21 des premières rangées, la seconde combobox wpf va d'abord parcourir les rangées avant de faire défiler les colonnes. Essayez d'omettre les valeurs TabIndex définies manuellement! De cette façon, il utilise la tabulation automatisée WPF pour passer d'abord par les enfants puis par les frères et sœurs du XAML.

comme ceci:

     <ItemsControl ItemsSource="{Binding}" Name="myItemsControl"> 
          <ItemsControl.ItemTemplate> 
           <DataTemplate> 
            <Grid> 
             <Grid.ColumnDefinitions> 
              <ColumnDefinition Width="3*"/> 
              <ColumnDefinition Width="*"/> 
              <ColumnDefinition Width="Auto"/> 
             </Grid.ColumnDefinitions> 
             <Grid.RowDefinitions> 
              <RowDefinition Height="Auto"/> 
             </Grid.RowDefinitions> 
             <ComboBox Grid.Column="0" ItemsSource="{Binding Source={StaticResource SomeItems}}" IsSynchronizedWithCurrentItem="False" SelectedItem="{Binding Path=SomeValue, Mode=TwoWay}" DisplayMemberPath="Name"/> 
             <ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource SomeOtherItems}}" IsSynchronizedWithCurrentItem="False" SelectedItem="{Binding Path=SomeOtherValue, Mode=TwoWay}" DisplayMemberPath="Value"/> 
             <TextBox HorizontalContentAlignment="Stretch" Grid.Column="2" LostKeyboardFocus="TextBox_FormatAfterLostFocus"> 
              <TextBox.Text> 
               <Binding Path="Wert" Mode="TwoWay" /> 
              </TextBox.Text> 
             </TextBox> 
            </Grid> 
           </DataTemplate> 
          </ItemsControl.ItemTemplate> 
         </ItemsControl> 
+0

pour quoi faire -1? –