How can I make a sound in a WPF app in Visual Studio using a controller?

0

very good, I'm trying to make a driver, specifically a button that when pressed, the WPF interface of Visual Studio gives me a simple sound (as if it is wav or mp3 format), however everything I've seen to do so they perform in Windows Forms and nobody has done it in a WPF, it is not possible to do it or simply people prefer to do it in the other. Anyone have an idea of how it could be done in WPF?

    
asked by Daniel Potrimba 26.05.2017 в 11:17
source

1 answer

0

Add it directly as a trigger in the XAML tag, something like this:

<Button Content ="Play">
   <Button.Style>
    <Style>
     <Style.Triggers>
      <EventTrigger RoutedEvent="Button.Click">
       <EventTrigger.Actions>
        <SoundPlayerAction Source="02 Best I Ever Had.wav"></SoundPlayerAction>
       </EventTrigger.Actions>
      </EventTrigger>
     </Style.Triggers>
    </Style>
   </Button.Style>
  </Button>

You will need to reference the namespace System.Media.SoundPlayer

    
answered by 28.05.2017 / 00:53
source