It's not that hard, although it took me some time to find it.
First offcourse you use the mediaelement control.
<FlipView x:Name="FvGallery" Width="800" Height="600" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image x:Name="Pic1" Source="Assets/monument.jpg" Stretch="Fill" />
<Image x:Name="Pic2" Source="assets/mountain.jpg" Stretch="Fill"/>
<Image x:Name="Pic3" Source="assets/ocean.jpg" Stretch="Fill"/>
<Image x:Name="Pic4" Source="assets/sand.jpg" Stretch="Fill"/>
<Image x:Name="Pic5" Source="assets/tree.jpg" Stretch="Fill"/>
</FlipView>
<MediaElement x:Name="Cart1" AutoPlay="False" Volume="100" MediaOpened="Tone_MediaOpened" />
In my situation I created an array with sounds
Dim ReadOnly _sounds() as String = {"ms-appx://./assets/cartoon021.wav",
"ms-appx://./assets/cartoon026.wav", _
"ms-appx://./assets/cartoon028.wav", _
"ms-appx://./assets/cartoon032.wav", _
"ms-appx://./assets/cartoon041.wav"}
after that I created a method which I call in the SelectionChanged subroutine from the flipview
Private Sub DoSound(ByVal wav As String )
Dim sound as Uri = New Uri(wav) '"ms-appx://./assets/cartoon032.wav"
Me.Cart1.Source = sound
InitializePropertyValues()
Me.Cart1.Play()
End Sub
old code but still in the project:
Private sub InitializePropertyValues()
Cart1.Volume = 100
End sub
private sub Tone_MediaOpened (sender As Object, e As RoutedEventArgs)
Cart1.Play()
end sub
And as last, the code from SelectionChanged
Private Sub FvGallery_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles FvGallery.SelectionChanged
dim fv as FlipView = sender
dim item as Integer = fv.SelectedIndex
DoSound(_sounds(item))
End Sub
Strange thing is that you don't hear sound if you debug, you only hear sound if you start the app the normal way.