ControlTemplate 内に InputBindings (Enter の KeyBinding) を持つ TextBox の WPF スタイルを作成しました。Style と InputBindings は TextBox に対して正常に機能していますが、この Style を TextBox に使用すると、TabOrder/TabStop が機能しなくなります。
これはスタイルです:
<Style x:Key="TextBoxTemplate" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="FontSize" Value="16"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Margin" Value="5,0,5,5"/>
<Setter Property="Width" Value="150"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBox Text="{TemplateBinding Text}">
<TextBox.InputBindings>
<KeyBinding Command="{Binding EnterKeyCommand}" Key="Enter"/>
</TextBox.InputBindings>
</TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
TextBoxes に追加する方法:
<TextBox Text={Binding FirstName} Style="{StaticResource TextBoxTemplate}">
<TextBox Text={Binding LastName} Style="{StaticResource TextBoxTemplate}">
問題は、ControlTemplate 内で TextBox を使用していることだと思います。しかし、テンプレート内の TextBox なしで InputBindings を実行する方法がわかりません
何か考えはありますか?ありがとうフィル