在我看来,最简单的方法是使用KeyBinding,它允许您将KeyGesture绑定到ICommand实现。
在您的情况下,您可以在 XAML 中编写如下内容:
<TextBox AcceptsReturn="False">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding YourCommand}" />
</TextBox.InputBindings>
</TextBox>
Run Code Online (Sandbox Code Playgroud)
因此,当您TextBox专注并按下 时Enter,YourCommand将被执行。
我希望它能帮助你。