Hi,
In my WPF application I have a text box control. The text box control is located in a UserControl which in turn has a View Model class. In my VM class I have a Command, which get executed either when a button is clicked in UserControl or when the Enter key is pressed. My problem is that when I press Enter, the text box loses focus and I have to click on the text box to get it focused again. What can I do to make the textbox keep focus when the key is pressed ?
I try to make a sketch on what I'm using right now:
<Window>
<uc:DesignPanel ... />
<uc:CommandPrompt ... />
</Window>
<UserControl Name=CommandPrompt ...>
<StackPanel>
<TextBox Name="tb_commands" />
<Button Name="btn_process" FocusManager.FocusedElement="{Binding ElementName=tb_commands}" />
</StackPanel>
</UserControl>
The DesignPanel user control in turn contains other user controls (UCOperands). The UCOperand basically looks like this:
<UserControl Name="UCOperand" Focusable="true">
<UserControl.InputBindings ... />
</UserControl>
Note here that I have set Focusable="true" on the UCOperand, this is needed because otherwise the user cannot invoke the input commands defined on this contrl. If I remove this property or set it to false, then everything works just as I expect, e.g. when I press Enter while I'm editing the "tb_commands" text box or click on "btn_process" button the focus is kept on the text box. But as it is now, whenever hit Enter or click on the button, the tb_commands loses focus.
Thanks in advance.