Page 1 of 1

Pressing gamepad B button on a Textbox

Posted: 18 Jun 2020, 05:36
by IanM
I'm having some trouble getting my BackCommand to execute when pressing the Gamepad B button on a Textbox.

Instead of calling my BackCommand it de-focuses the text entry and I have to press it a second time for it to work.
Pressing the escape key calls my BackCommand first time with no problems.
<TextBox x:Name="FirstNameTextbox" Text="{Binding PlayerFirstName}">
    <i:Interaction.Triggers>
        <noesis:GamepadTrigger FiredOn="ButtonDown" Button="Accept">
            <i:InvokeCommandAction Command="{Binding CloseNamePopupCommand}" />
        </noesis:GamepadTrigger>
    </i:Interaction.Triggers>
    <TextBox.InputBindings>
        <KeyBinding Key="Esc" Command="{Binding BackCommand}"/>
        <KeyBinding Key="Enter" Command="{Binding CloseNamePopupCommand}"/>
    </TextBox.InputBindings>
</TextBox>
Any ideas what I am missing?

Re: Pressing gamepad B button on a Textbox

Posted: 19 Jun 2020, 16:36
by sfernandez
The TextBox control has focus engagement enabled by default so when it gets focused, using the directional navigation doesn't get trapped trying to move the cursor through the text. Instead you have to press Accept (A) button to "engage" the focus and start writing/moving cursor around, and press Cancel (B) button to "disengage" the focus.

Is that what you are seeing?

If you don't want that behavior in your TextBox you can set IsFocusEngagementEnabled property to false (this is in 3.0, in previous 2.2 version the property name was SupportsFocusEngagement).

Re: Pressing gamepad B button on a Textbox

Posted: 22 Jun 2020, 06:23
by IanM
Setting SupportsFocusEngagement to false was what I wanted.
Thanks.

Re: Pressing gamepad B button on a Textbox

Posted: 22 Jun 2020, 11:42
by sfernandez
Great, thanks for the update.

Re: Pressing gamepad B button on a Textbox

Posted: 23 Jun 2020, 02:10
by IanM
We have just realised that this solution does not fully work for us.
Setting SupportsFocusEngagement to false allow us to call our BackCommand with just one Cancel input, but when focussing the textbox again we can't input text.
So I assume that setting SupportsFocusEngagement to false has skipped some functionality that was required.

Re: Pressing gamepad B button on a Textbox

Posted: 23 Jun 2020, 11:55
by sfernandez
This is a bug, TextBox should work fine with IsFocusEngagementEnabled="False". I reproduced the problem and we will fix it for the next release: #1732

Anyway, just to understand better your scenario, do you want to execute the BackCommand to close the screen where the TextBox is being edited?
Does the screen contain more TextBoxes or controls apart from "FirstNameTextbox"?
Because if you have more textboxes and disable the focus engagement, you won't be able to navigate through them using the gamepad.

Re: Pressing gamepad B button on a Textbox

Posted: 24 Jun 2020, 05:35
by IanM
The screen that I am working on contains two textboxes (first name and surname).
When the user chooses to change the first name we manually set focus (via c++ code) to the first name textbox when we display the textbox to the user.
Then when the user is done the back command will hide the textbox and manually return focus to the original UI element.

Re: Pressing gamepad B button on a Textbox

Posted: 24 Jun 2020, 11:43
by sfernandez
Then it looks like disabling IsFocusEngagementEnabled on that TextBox is the correct approach, because you don't need to move focus to other control using the gamepad while editing the name. We fixed the bug #1732 for the next release so you can use it.