Windows phone 7 MediaElement Windows Phone 8
我正在列表框中显示歌曲列表我已绑定媒体元素,但无法在songs.cs文件中获取媒体元素名称实例,无法播放歌曲Windows phone 7 MediaElement Windows Phone 8,windows-phone-7,windows-phone-8,windows-phone,Windows Phone 7,Windows Phone 8,Windows Phone,我正在列表框中显示歌曲列表我已绑定媒体元素,但无法在songs.cs文件中获取媒体元素名称实例,无法播放歌曲 <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <MediaElement Name="Player" Source="{B
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<MediaElement Name="Player" Source="{Binding SongUrl}" AutoPlay="False"/>
<Button Name="Click" Click="Play_Click" Content="Button"/>
<StackPanel Width="150" Height="50">
<TextBlock Text="{Binding SongName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" TextAlignment="Center" Foreground="Red" FontSize="16"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
媒体播放器不应该在ItemTemplate中,因为我相信您一次只能播放一个声音(为每个项目使用媒体元素会很昂贵)。因此,您应该将MediaLayer移至外部,然后单击“执行”按钮:
private void Play_Click(object sender, RoutedEventArgs e)
{
Button button=sender as Button;
Player.Source=((Item)button.DataContext).SongUrl
Player.play(); (unable to get Media Element name)
}
Player.Source=((Item)button.DataContext.SongUrl)Item的意思是什么您需要用SongUrl所在的任何类替换Item,因为我没有类名,所以只使用了一个临时名称
private void Play_Click(object sender, RoutedEventArgs e)
{
Button button=sender as Button;
Player.Source=((Item)button.DataContext).SongUrl
Player.play(); (unable to get Media Element name)
}