Sound triggers for custom controls
Hi, I'm trying to hook up UI sounds to my custom controls, but I'm having a few issues.
Firstly, the screen I'm implementing looks like this: A custom tab control contains two tab items, and each tab item has a list box inside it.
The main purpose of the tab control is to implement code behind for switching tabs based on gamepad bumper input which looks like this:
In my style for the custom tab control, I've got the following code for triggering UI sounds.
However, I can't get it to work. I can't get KeyTriggers or GamepadTriggers to fire my PlaySoundAction. Using EventTriggers does in fact work, but I wanted to play sounds on key presses in this situation. I'm not quite sure what the expected approach is for this issue.
Another issue I'm having is that if I do try to use an EventTrigger instead, like "SelectionChanged" in the tab control, it fires when the list box's selection changes as well!! Since the list box is in the content of the tab item. So that approach doesn't really work either.
Firstly, the screen I'm implementing looks like this: A custom tab control contains two tab items, and each tab item has a list box inside it.
The main purpose of the tab control is to implement code behind for switching tabs based on gamepad bumper input which looks like this:
Code: Select all
void CustomTabControl::OnKeyUp(const KeyEventArgs& e)
{
// Uses SetFocus from base TabItem. This also attempts to traverse focus to the content of the tab item.
switch (e.key)
{
case Key_PageLeft: {
CustomTabItem* nextTabItem = FindNextTabItem(GetSelectedIndex(), -1);
nextTabItem->Focus(); // Set focus to the tab item
e.handled = nextTabItem->SetFocus(); // Traverse focus to the tab item's selected content
break;
}
case Key_PageRight: {
CustomTabItem* nextTabItem = FindNextTabItem(GetSelectedIndex(), 1);
nextTabItem->Focus(); // Set focus to the tab item
e.handled = nextTabItem->SetFocus(); // Traverse focus to the tab item's selected content
break;
}
default:
break;
}
}
In my style for the custom tab control, I've got the following code for triggering UI sounds.
Code: Select all
<Style TargetType="{x:Type local:CustomTabControl}">
...
<Setter Property="noesis:StyleInteraction.Triggers">
<Setter.Value>
<noesis:StyleTriggerCollection>
<noesis:GamepadTrigger Button="PageLeft">
<b:PlaySoundAction Source="menutab"/>
</noesis:GamepadTrigger>
<noesis:GamepadTrigger Button="PageRight">
<b:PlaySoundAction Source="menutab"/>
</noesis:GamepadTrigger>
</noesis:StyleTriggerCollection>
</Setter.Value>
</Setter>
</Style>
Another issue I'm having is that if I do try to use an EventTrigger instead, like "SelectionChanged" in the tab control, it fires when the list box's selection changes as well!! Since the list box is in the content of the tab item. So that approach doesn't really work either.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Sound triggers for custom controls
Hello,
I don't think you need to create a custom TabControl to handle tab switching with the gamepad. Our default implementation already supports it, you can use the gamepad bumpers to switch between tabs if the focus is inside the TabControl or in the tab headers.
Regarding the playing of sounds the problem is that the TabControl is handling the KeyDown event, so it won't be received by the GamepadTrigger. You should listen to the button up, something like this:
Could you try that? It is working fine in my tests.
I don't think you need to create a custom TabControl to handle tab switching with the gamepad. Our default implementation already supports it, you can use the gamepad bumpers to switch between tabs if the focus is inside the TabControl or in the tab headers.
Regarding the playing of sounds the problem is that the TabControl is handling the KeyDown event, so it won't be received by the GamepadTrigger. You should listen to the button up, something like this:
Code: Select all
<noesis:GamepadTrigger Button="PageLeft" FiredOn="ButtonUp" ActiveOnFocus="True">
<b:PlaySoundAction Source="menutab"/>
</noesis:GamepadTrigger>
<noesis:GamepadTrigger Button="PageRight" FiredOn="ButtonUp" ActiveOnFocus="True">
<b:PlaySoundAction Source="menutab"/>
</noesis:GamepadTrigger>Re: Sound triggers for custom controls
Hey thanks for the reply.
On the custom Tab Control, we were using the default implementation originally but I believe we wanted tabs changing on key up, as well as the option in the future to remap tabbing to triggers instead of bumpers in some situations.
For the sound triggers, your solution worked perfectly! Thanks for the simple fix.
On the custom Tab Control, we were using the default implementation originally but I believe we wanted tabs changing on key up, as well as the option in the future to remap tabbing to triggers instead of bumpers in some situations.
For the sound triggers, your solution worked perfectly! Thanks for the simple fix.
Re: Sound triggers for custom controls
Thanks for the feedback. Marking this as solved.
Who is online
Users browsing this forum: Bing [Bot] and 6 guests