C# Code, Tutorials and Full Visual Studio Projects

Play Sounds in WPF with PlaySoundAction Behavior

Posted by on Jun 22, 2012 in Code Snippets, Sound | 1 comment

If you use Expression Blend you have the option to use Behaviors to help with your coding. One such behavior is the PlaySoundAction behavior. This one lets you play a sound with just XAML code.

Here is an example:

<Button Content="Button" Height="28" Canvas.Left="145" Canvas.Top="369" Width="48">
    	<i:EventTrigger EventName="Click">
    		<ei:PlaySoundAction Source="beep-3.wav"/>

In this example when the button is pressed a noise will play. Keep in mind the sound file needs to have a “Build Action” of “Content”, and a “Copy to Output Directory” of “Copy if newer” or “Copy always”

One Comment

Join the conversation and post a comment.

  1. Owen Johnson

    What xmlns do i need to add as i and ei?

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>