Search code examples
c#wpfxamlembedded-resource

Embedd audio file for usage in wpf custom control template


I'm building a custom control library, that directly contains some audio files. They should be embedded in the library.

Now I want to play such an audio file on a custom button press:

    <ControlTemplate.Triggers>
                        <EventTrigger RoutedEvent="PreviewMouseDown">
                            <SoundPlayerAction Source="pack://application:,,,/CustomControlLibrary1;component/Audio/buttonPress.wav" />
                        </EventTrigger>
                        ...

When I include the library in a project, an error occured on starting:

Cannot locate resource 'audio/buttonPress.wav'.

I set the Build Action of every audio file to "Embedded Resource", but the error still occurs.

I'm trying to fix this issue for ages. What the hell I'm making wrong?


Solution

  • The build action must be Resource, not Embedded Resource. See also this answer.