How to best template bind a TriggerAction property
Posted: 02 Jun 2026, 15:31
Hey All,
I've recently been refactoring some code in our codebase regarding button SFX playing when a mouse enters it and have largely resolved it but am struggling to do the last 5% and have not found a workable solution online so hoping someone here can help! This is all in Unity using C# just for clarity.
I have written the below code with some back and forth with the intent of playing sound effects in the UI and binding to the Sound property so that other devs can simply bind a value of eSFX (an enum we use for various sound effects).
Below is the intended base style a few other button styles would base themselves upon and as written below the correct sound effect does indeed play, FX_METAL_ROLLOVER6 being one of the enum values of the eSFX enum.
However when I update to the below code, the debug log informs be it's play 'FX_Null' which is the default value of the eSFX enum e.g. Nothing is being correctly assigned.
Here is an example of ho we'd want/expect it to work. The key thing I expected to happen is with the binding of the enum value at the button level, the templatebinding would then update the sound property on the PlaySoundUIAction and play that sound. What I want to understand is why this isn't the case and how to best implement this TriggerAction property in such a way that we can simply bind the enum value at the button level, rather than at the style level, in order to be able to quickly swap what SFX the button players when a mouse enters its UI space.
Thanks in advance for any and all help, I have a feeling it might be simple to resolve but have had little luck in resolving it!
I've recently been refactoring some code in our codebase regarding button SFX playing when a mouse enters it and have largely resolved it but am struggling to do the last 5% and have not found a workable solution online so hoping someone here can help! This is all in Unity using C# just for clarity.
I have written the below code with some back and forth with the intent of playing sound effects in the UI and binding to the Sound property so that other devs can simply bind a value of eSFX (an enum we use for various sound effects).
Code: Select all
public class PlayUISoundAction : TriggerAction<DependencyObject>
{
public static DependencyProperty SoundProperty = DependencyProperty.Register("Sound", typeof(eSFX), typeof(PlayUISoundAction), new PropertyMetadata(eSFX.FX_NULL));
public eSFX Sound
{
get => (eSFX)GetValue(SoundProperty);
set { SetValue(SoundProperty, value); }
}
protected override void Invoke(object parameter)
{
#if NOESIS
UnityEngine.Debug.Log($"The sound selected is: {Sound}");
SFXManager.instance.playUISound((int)Sound);
#endif
}
}
Code: Select all
<Style x:Key="BTN_SH_Glow_Base" TargetType="{x:Type Button}">
<Setter Property="noesis:StyleInteraction.Triggers">
<Setter.Value>
<noesis:StyleTriggerCollection>
<b:EventTrigger EventName="MouseEnter">
<local:PlayUISoundAction Sound="FX_METAL_ROLLOVER6"/>
</b:EventTrigger>
</noesis:StyleTriggerCollection>
</Setter.Value>
</Setter>
</Style>
Code: Select all
<Style x:Key="BTN_SH_Glow_Base" TargetType="{x:Type Button}">
<Setter Property="noesis:StyleInteraction.Triggers">
<Setter.Value>
<noesis:StyleTriggerCollection>
<b:EventTrigger EventName="MouseEnter">
<local:PlayUISoundAction Sound="{TemplateBinding local:PropEx.MouseOverSFX}"/>
</b:EventTrigger>
</noesis:StyleTriggerCollection>
</Setter.Value>
</Setter>
</Style>
Code: Select all
<Button
Name="ButtonResume"
Width="300"
Margin="0,10,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
local:PropEx.TextCentre="{Binding Source={x:Static local:Translate.Instance}, Path=GameTexts[TEXT_GAME_OPTIONS_011]}"
local:PropEx.TextLeft=""
local:PropEx.TextRight=""
local:PropEx.MouseOverSFX="{x:Static Enums:eSFX.FX_METAL_ROLLOVER6}"
Command="{Binding HUDIngameMenu.ButtonIngameMenuCommand}"
CommandParameter="8"
RenderTransformOrigin="0.5,0.5"
Style="{StaticResource BTN_SH_GlowSDisable}"/>