Я создал стиль WPF для TextBox с InputBindings (KeyBinding для Enter) внутри ControlTemplate. Style и InputBindings отлично работают для моих текстовых полей, но если я использую этот стиль для своих текстовых полей, 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>
Как я добавляю его в свои текстовые поля:
<TextBox Text={Binding FirstName} Style="{StaticResource TextBoxTemplate}">
<TextBox Text={Binding LastName} Style="{StaticResource TextBoxTemplate}">
Я думаю, проблема в том, что я использую TextBox внутри ControlTemplate. Но я не знаю, как запустить InputBindings без TextBox внутри шаблона.
Есть ли у вас какие-либо идеи? Спасибо, Фил.