I’m trying to set the source of a media element in C#. This is what I’m doing
XAML Part
<MediaElement x:Name="Sound" AutoPlay="False" />
<Button Content="Shout!" Height="123" Name="button2" Width="123" Click="shout_Click" />
C# Part
private void shout_Click(object sender, RoutedEventArgs e)
{
this.Sound.Source = new Uri("Sounds/fusrodah.wma", UriKind.Relative);
this.Sound.Play();
}
The above doesn’t work. However, If i set the path manually in the xaml it works. How can I set the a MediaElement‘s source in C#?
Do you get an error, or does it just not play? Try adding a forward slash, Dovahkiin: