Adding sound to buttons with a ResourceDictionary
Posted: 18 Jan 2023, 11:23
Hi,
so I've recently learned about ResourceDictionary's. I've taken a button from a Noesis Example which plays a sound if you hover over them.
I want all my buttons to make this sound on hover, so I want to use a ResourceDictionary to do it.
I've tried multiple things, but I'm still getting error messages. My most recent attempt can be seen below.
Is there a way to achieve this?
Thanks in advance.
so I've recently learned about ResourceDictionary's. I've taken a button from a Noesis Example which plays a sound if you hover over them.
I want all my buttons to make this sound on hover, so I want to use a ResourceDictionary to do it.
I've tried multiple things, but I'm still getting error messages. My most recent attempt can be seen below.
Is there a way to achieve this?
Thanks in advance.
Code: Select all
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions" xmlns:b1="clr-namespace:Noesis;assembly=Noesis.GUI">
<ControlTemplate TargetType="Button" x:Key="InteractiveButton">
<ControlTemplate.Triggers>
<b:EventTrigger EventName="MouseEnter">
<noesis:SetFocusAction/>
</b:EventTrigger>
<b:EventTrigger EventName="GotFocus">
<b:PlaySoundAction Source="../../Art/Audio/Sounds/ButtonHover.mp3" Volume="1.0"/>
</b:EventTrigger>
<b:EventTrigger EventName="Click">
<b:PlaySoundAction Source="../../Art/Audio/Sounds/ButtonClick.mp3" Volume="1.0"/>
</b:EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ResourceDictionary>
Code: Select all
<UserControl x:Class="MyEngineBuilder.MainMenuView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
d:DesignWidth="1280" d:DesignHeight="720"
Focusable="True">
<UserControl.Resources>
<ResourceDictionary Source="../ButtonDictionary.xaml"/>
</UserControl.Resources>
<Button>I want to make a sound!<Button/>
<UserControl/>