windows phone 7中MediaElement的源设置

本文关键字:设置 MediaElement phone windows | 更新日期: 2023-09-27 18:18:49

我正在尝试设置c#中媒体元素的来源。这就是我要做的

XAML Part

<MediaElement x:Name="Sound" AutoPlay="False" />
<Button Content="Shout!" Height="123" Name="button2" Width="123" Click="shout_Click" />
<<p> c#部分/strong>
private void shout_Click(object sender, RoutedEventArgs e)
        {
            this.Sound.Source = new Uri("Sounds/fusrodah.wma", UriKind.Relative);
            this.Sound.Play();
        }

以上内容不起作用。但是,如果我在xaml中手动设置路径,它可以工作。如何在c#中设置a MediaElement的源?

windows phone 7中MediaElement的源设置

你得到一个错误,还是它只是不播放?尝试添加一个正斜杠,Dovahkiin:

this.Sound.Source = new Uri("/Sounds/fusrodah.wma", UriKind.Relative);