User avatar
Sierra
Topic Author
Posts: 22
Joined: 10 Jun 2024, 09:28

Remapping TabControl selection from L1/R1 to L2/R2

15 Jul 2024, 15:33

Hey there!

We have a UI screen with a primary TabControl navigation and a secondary TabControl navigation nested in it. By default TabControl supports switching the selected TabItem with the L1/R1. Which works great when you have a single TabControl, but it kind of breaks down in our case. At the moment, to change the tabs in the secondary nested TabControl the focus first needs to shift to it.

We would like to remap the secondary TabControl to switch its TabItems with L2/R2 and make it independent of where the focus is. We thought that we could utilize the GamepadTrigger for this, but we are not sure how to evoke the change. Is there an existing command for this already? Do we have to write it ourselves?

Cheers!
 
Rmunoz
Posts: 13
Joined: 27 Aug 2022, 20:44

Re: Remapping TabControl selection from L1/R1 to L2/R2

16 Jul 2024, 18:20

I think you could implement this kind of behavior by disabling the default TabControl selection management completely from both TabControls.
Then implement the reaction to buttons directly at the root of the document.
You could prevent TabControl and TabItems from receiving keyboard focus using Focusable property, and then hook to the keys you want to control the change of SelectedIndex

I've drafted the general idea on the following xamltoy ( not fully working yet, but you can see the idea)


Btw you can ignore all the weird local resources on TabItems, is just a hacky way I've implemented to move next and previous selected item.
Also added at the bottom some basic diagnostics fields while I'm working on it.

Update: Managed to make it work with Keys. Clicking on the items not working properly for now.
 
tantitem
Posts: 2
Joined: 12 Jul 2024, 10:08

Re: Remapping TabControl selection from L1/R1 to L2/R2

17 Jul 2024, 05:36

Is there a way to programmatically set focus on the secondary TabControlgeometry dash to enable the L1/R1 switching behavior?
 
Rmunoz
Posts: 13
Joined: 27 Aug 2022, 20:44

Re: Remapping TabControl selection from L1/R1 to L2/R2

18 Jul 2024, 15:57

As far as I know it already implements what was requested.
After clicking on the right path you should be able to navigate with the keys specified on screen.

I believe the requirement to click on the right part of the screen is for focusing on that part of the web and not about the focus on noesis specifically.
You can confirm this behavior in the Detroit sample, you also need to click on the right side of the web before you can control using keys.


 
User avatar
Sierra
Topic Author
Posts: 22
Joined: 10 Jun 2024, 09:28

Re: Remapping TabControl selection from L1/R1 to L2/R2

22 Jul 2024, 10:52

I think you could implement this kind of behavior by disabling the default TabControl selection management completely from both TabControls.
Then implement the reaction to buttons directly at the root of the document.
You could prevent TabControl and TabItems from receiving keyboard focus using Focusable property, and then hook to the keys you want to control the change of SelectedIndex

I've drafted the general idea on the following xamltoy ( not fully working yet, but you can see the idea)


Btw you can ignore all the weird local resources on TabItems, is just a hacky way I've implemented to move next and previous selected item.
Also added at the bottom some basic diagnostics fields while I'm working on it.

Update: Managed to make it work with Keys. Clicking on the items not working properly for now.
Heya! This actually looks like it could work! I'll try it out and report back on my findings, thanks a lot! ^^
 
User avatar
sfernandez
Site Admin
Posts: 3109
Joined: 22 Dec 2011, 19:20

Re: Remapping TabControl selection from L1/R1 to L2/R2

24 Jul 2024, 13:07

Thanks @Rmunoz for the suggestion, it is very similar to what I was going to suggest: defining the GamepadTriggers in the root of the document. One improvement I would consider is using a converter to change the tab index, for example:
<noesis:GamepadTrigger Button="PageUp">
  <b:ChangePropertyAction TargetName="InnerTabControl" Property="SelectedIndex"
    Value="{Binding SelectedIndex, ElementName=InnerTabControl,
      Converter={StaticResource AddConverter}, ConverterParameter=-1}"/>
</noesis:GamepadTrigger>
<noesis:GamepadTrigger Button="PageDown">
  <b:ChangePropertyAction TargetName="InnerTabControl" Property="SelectedIndex"
    Value="{Binding SelectedIndex, ElementName=InnerTabControl,
      Converter={StaticResource AddConverter}, ConverterParameter=1}"/>
</noesis:GamepadTrigger>
 
User avatar
Sierra
Topic Author
Posts: 22
Joined: 10 Jun 2024, 09:28

Re: Remapping TabControl selection from L1/R1 to L2/R2

24 Jul 2024, 14:44

Thanks @Rmunoz for the suggestion, it is very similar to what I was going to suggest: defining the GamepadTriggers in the root of the document. One improvement I would consider is using a converter to change the tab index, for example:
<noesis:GamepadTrigger Button="PageUp">
  <b:ChangePropertyAction TargetName="InnerTabControl" Property="SelectedIndex"
    Value="{Binding SelectedIndex, ElementName=InnerTabControl,
      Converter={StaticResource AddConverter}, ConverterParameter=-1}"/>
</noesis:GamepadTrigger>
<noesis:GamepadTrigger Button="PageDown">
  <b:ChangePropertyAction TargetName="InnerTabControl" Property="SelectedIndex"
    Value="{Binding SelectedIndex, ElementName=InnerTabControl,
      Converter={StaticResource AddConverter}, ConverterParameter=1}"/>
</noesis:GamepadTrigger>
Would this overwrite the default built-in behaviour of switching tabs with L1/R1 when focusing the TabControl? I'd like to avoid a case where the Child Tab Control can be controlled by both the triggers and the bumpers xD

As for the Converter - I see you are loading a StaticResource AddConverter. What does that resource actually represent? I've not used converters much hence my questions.
 
User avatar
sfernandez
Site Admin
Posts: 3109
Joined: 22 Dec 2011, 19:20

Re: Remapping TabControl selection from L1/R1 to L2/R2

29 Jul 2024, 17:58

Would this overwrite the default built-in behaviour of switching tabs with L1/R1 when focusing the TabControl? I'd like to avoid a case where the Child Tab Control can be controlled by both the triggers and the bumpers xD
No, built-in behavior will still be there. To get rid of that behavior those keys (L1/R1 == Gamepad_PageLeft/Gamepad_PagRight) should be handled before reaching the TabControl, or extend the TabControl to override that behavior.
As for the Converter - I see you are loading a StaticResource AddConverter. What does that resource actually represent? I've not used converters much hence my questions.
Converters are used in bindings to transform values to the desired result. Those converters are classes that need to be created by programmers and registered, then you can define them as resources in any ResourceDictionary. In this example I was assuming there is an AddConverter that takes an integer (from the binding) and adds the value of the ConverterParameter. The idea was to add/remove one from the current SelectedIndex.
 
User avatar
Sierra
Topic Author
Posts: 22
Joined: 10 Jun 2024, 09:28

Re: Remapping TabControl selection from L1/R1 to L2/R2

30 Jul 2024, 12:12

Would this overwrite the default built-in behaviour of switching tabs with L1/R1 when focusing the TabControl? I'd like to avoid a case where the Child Tab Control can be controlled by both the triggers and the bumpers xD
No, built-in behavior will still be there. To get rid of that behavior those keys (L1/R1 == Gamepad_PageLeft/Gamepad_PagRight) should be handled before reaching the TabControl, or extend the TabControl to override that behavior.
As for the Converter - I see you are loading a StaticResource AddConverter. What does that resource actually represent? I've not used converters much hence my questions.
Converters are used in bindings to transform values to the desired result. Those converters are classes that need to be created by programmers and registered, then you can define them as resources in any ResourceDictionary. In this example I was assuming there is an AddConverter that takes an integer (from the binding) and adds the value of the ConverterParameter. The idea was to add/remove one from the current SelectedIndex.
Thank you for answering. How would I disable the default behavior of L1/R1 for the child TabControl, while also ensuring that it continues working for the parent TabControl?
 
User avatar
sfernandez
Site Admin
Posts: 3109
Joined: 22 Dec 2011, 19:20

Re: Remapping TabControl selection from L1/R1 to L2/R2

01 Aug 2024, 10:47

How would I disable the default behavior of L1/R1 for the child TabControl, while also ensuring that it continues working for the parent TabControl?
One way could be by defining a Behavior that hooks to the PreviewKeyDown and sets the e.handled=True when Gamepad_PageLeft/PageRight are pressed. That way you can decide on which TabControls you want to disable those keys to switch tabs.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest