The SystemSounds class provides some system sounds, they have a Play() method. To use this in XAML, you will either have to resort to some kind of furious hacks, implement a lot of custom logic or use Blend Interactivity to define your own TriggerAction, which can use SystemSound and play it.
Interaction Method:
public class SystemSoundPlayerAction : System.Windows.Interactivity.TriggerAction<Button> { public static readonly DependencyProperty SystemSoundProperty = DependencyProperty.Register("SystemSound", typeof(SystemSound), typeof(SystemSoundPlayerAction), new UIPropertyMetadata(null)); public SystemSound SystemSound { get { return (SystemSound)GetValue(SystemSoundProperty); } set { SetValue(SystemSoundProperty, value); } } protected override void Invoke(object parameter) { if (SystemSound == null) throw new Exception("No system sound was specified"); SystemSound.Play(); } }
<Window xmlns:sysmedia="clr-namespace:System.Media;assembly=System" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"> ... <Button Content="Test2"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:EventTrigger.Actions> <local:SystemSoundPlayerAction SystemSound="{x:Static sysmedia:SystemSounds.Beep}"/> </i:EventTrigger.Actions> </i:EventTrigger> </i:Interaction.Triggers> </Button>
(I don't know if SystemSounds.Beep one you are looking for.)
David Winman Note:
For others studying this issue, the Blend interactivity mentioned in the answer requires a link to System.Windows.Interactivity.dll, which is located in C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries\
source share