7

動的に読み込まれるコントロールのタブ オーダー (tabindex) を設定しようとしている状況があります。メインの XAML は次のようになります。

<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding ItemsDataSource}" Name="overlayItems" ItemTemplate="{StaticResource DetailsTemplate}">
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel Orientation="Vertical"/>
    </ItemsPanelTemplate>
   </ItemsControl.ItemsPanel>
</ItemsControl>

例として、 DetailsTemplate が次のような単純なものであると仮定します。

<DataTemplate x:Key="DetailsTemplate">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="50" />
      <ColumnDefinition Width="150" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="22" />
      <RowDefinition Height="22" />
      <RowDefinition Height="22" />
    </Grid.RowDefinitions>

    <Label Grid.Column="0" Grid.Row="0" Padding="0">Field 1</Label>
    <TextBox Grid.Column="1" Grid.Row="0" Name="field1TextBox" TabIndex="0" Text="{Binding Field1Value}"/>

    <Label Grid.Column="0" Grid.Row="1" Padding="0">Field 2</Label>
    <TextBox Grid.Column="1" Grid.Row="1" Name="field2TextBox" TabIndex="1" Text="{Binding Field2Value}"/>

    <Label Grid.Column="0" Grid.Row="2" Padding="0">Field 3</Label>
    <TextBox Grid.Column="1" Grid.Row="2" Name="field3TextBox" TabIndex="2" Text="{Binding Field3Value}"/>
  </Grid>
</DataTemplate>

この XAML は、結果のタブ オーダーを除いて問題なく動作します。

ItemsDataSource がクラスのコレクションであり、そのクラスの 3 つのインスタンスが含まれていると仮定すると、DetailsTemplate データ テンプレートの 3 つのセットが作成されます。ただし、タブ オーダーは変更されず、すべての field1TextBox は TabIndex 0 のままです。つまり、field1TextBox の最初のインスタンスから field2TextBox、field3TextBox にタブ移動する代わりに、タブは field1TextBox の最初のインスタンスから field1TextBox の 2 番目のインスタンスに移動します。 field1TextBox の 3 番目のインスタンス、次に field2TextBox の最初のインスタンス、というように続きます。私の質問は、たとえば、データ テンプレートの 2 番目のインスタンスのテキスト ボックスのタブ インデックスがそれぞれ 3、4、5 に更新される場合に、タブ オーダーを修正するにはどうすればよいですか?

4

1 に答える 1

5

答えは、MSDNのKeyboardNavigation.TabNavigation添付プロパティページにあります。このプロパティこのプロパティが設定されている要素の子の論理タブ ナビゲーション動作を取得または設定します

KeyboardNavigationMode使用される列挙には、さまざまな方法でタブの順序に影響を与える可能性のある値がいくつかありますが、値を求めLocalているため、タブ インデックスはこのコンテナー内のローカル サブツリーでのみ考慮され、... [ナビゲーションはエッジに到達したときに要素を含む]

<Grid KeyboardNavigation.TabNavigation="Local">
    ...
</Grid>
于 2014-01-28T21:44:19.437 に答える