Sound triggers for custom controls
Posted: 17 May 2024, 04:15
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.