Reputation:
I'm trying to get one style going that performs all of my triggers. This is what I have, but the SoundPlayerAction is not firing:
<Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="Border" Padding="2" SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Border.MouseDown">
<SoundPlayerAction Source="/sounds/simpleclick.wav"/>
</EventTrigger>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Upvotes: 3
Views: 6925
Reputation: 15227
I tested this XAML and the only problem is that your RoutedEvent is not firing. Border.MouseDown is definitely not going to work. If you are looking to play a sound when the item is selected (which is what it appears you are trying to do), try the GotFocus event.
So, change your EventTrigger to be:
<EventTrigger RoutedEvent="ListBoxItem.GotFocus">
For me, that worked and sound started playing.
Upvotes: 16