タブ オーダーが設定されたすぐに使えるコントロールを含む WPF ページがあります。
境界線/グリッド/テキスト ボックス/2 つの Repeatbuttons (上/下) を含むカスタム コントロール (NumericSpinner) があります。
2 つの問題:
1) カスタム セレクター コントロールのテキスト ボックスにいるとき、そこからタブでページ上の他のコントロールに移動できません。ただし、上下の矢印のいずれかをクリックした後、タブで他のコントロールに移動できます。
2) カスタム コントロールのテキスト ボックスにタブで移動できません。すべてのコントロールをタブで移動した後でのみ、カーソルがテキスト ボックスに表示されます (タブ アウトできません)。
環境:
<ComboBox Margin="97,315,21,0" Name="txtdweldatcdu" Style="{StaticResource fieldComboBoxStyle}" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" VerticalAlignment="Top" TabIndex="10" />
<WpfControls:NumericSpinner Margin="97,338,21,0" Name="txtdweldatpctcomplete" HorizontalAlignment="Left" VerticalAlignment="Top" AllowNegativeValues="True" MaxValue="100" TabIndex="11" />
<ComboBox Margin="97,363,21,0" Name="txtdweldatclass" Style="{StaticResource fieldComboBoxStyle}" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" VerticalAlignment="Top" TabIndex="12" />
カスタム コントロールの一部:
<Border BorderThickness="1" BorderBrush="Gray" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="20" Width="117">
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="98"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox Name="valueText"
BorderThickness="0"
Grid.RowSpan="2"
Style="{StaticResource spinnerTextBoxStyle}"
PreviewKeyDown="valueText_PreviewKeyDown"
PreviewTextInput="valueText_PreviewTextInput"
TextChanged="valueText_TextChanged"
IsReadOnly="{Binding ElementName=Spinner, Path=IsReadOnly}"
Text="{Binding ElementName=Spinner, Path=Value, Mode=TwoWay}"
KeyboardNavigation.IsTabStop="True"
AcceptsTab="True"/>
<RepeatButton Name="upButton" Style="{StaticResource spinnerRepeatButtonStyle}" Click="upButton_Click" Grid.Column="1" Grid.Row="0" Height="10" Width="18" VerticalAlignment="Top" HorizontalAlignment="Right" HorizontalContentAlignment="Center">
<Polygon HorizontalAlignment="Center" Points="3,2 2,3 4,3" Fill="Black" Stretch="Uniform" Stroke="Black" StrokeThickness="0" />
</RepeatButton>
<RepeatButton Name="downButton" Style="{StaticResource spinnerRepeatButtonStyle}" Click="downButton_Click" Grid.Column="1" Grid.Row="1" Height="10" Width="18" VerticalAlignment="Top" HorizontalAlignment="Right" HorizontalContentAlignment="Center">
<Polygon HorizontalAlignment="Center" Points="2,2 4,2 3,3" Fill="Black" Stretch="Uniform" Stroke="Black" StrokeThickness="0" />
</RepeatButton>
</Grid>
</Border>
カスタム コントロールは、xaml とコード ビハインド ファイルで構成されます。
すべてのコントロールを含む親 xaml ページは動的に読み込まれ、コード ビハインドは含まれません。
カスタム コントロールのコンストラクターで、テストとして次のように設定しました。
valueText.TabIndex = 3;
this.TabIndex = 3;
4回目にタブを押すと、実際にカーソルがテキストフィールドに移動しますが、タブから出ることができません。
これを念頭に置いて、最初のステップは、コントロールの分離コードで設定されるタブ オーダー番号を渡すことができるコントロール パラメーターを作成することです。
CustomTabIndex プロパティを作成しました。
/// <summary>
/// Custom tab index property
/// </summary>
public int CustomTabIndex
{
get { return (int)GetValue(CustomTabIndexProperty); }
set { SetValue(CustomTabIndexProperty, value); }
}
public static readonly DependencyProperty CustomTabIndexProperty =
DependencyProperty.Register("CustomTabIndex", typeof(int), typeof(NumericSpinner));
また、xaml で CustomTabIndex="3" を設定しようとすると、次のエラーが表示されます。
プロパティ「CustomTabIndex」はタイプ「NumericSpinner」で見つかりませんでした。
いくつかの支援をいただければ幸いです。