我正在通过构建类似WMP的应用程序来学习C#和WPF。下面的代码可以正常运行,从列表框中选择电影会在媒体元素中播放。我的问题是找不到一种自动开始下一个电影的方法。谢谢。
提供电影列表的xml文件:
湖泊 c:\movies\Lake.wmv
提供电影列表的xml文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
熊
c:\movies\Bear.wmv
湖泊 c:\movies\Lake.wmv
xaml
<Window x:Class="WpfAppPlaylistTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="425">
<Window.Resources>
<XmlDataProvider x:Key="myMoviesXML"
Source="c:\Movies\media1.xml"
XPath="media"
/>
</Window.Resources>
<Grid DataContext="{Binding ElementName=movieList, Path=SelectedItem}">
<ListBox ItemsSource="{Binding Source={StaticResource myMoviesXML}, XPath=//media//movie}" IsSynchronizedWithCurrentItem="True"
Name="movieList" HorizontalAlignment="Right" Width="114" Margin="0,48,12,32">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=title}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<MediaElement Source="{Binding XPath=filename}" LoadedBehavior="Play" Name="mediaElement1" Margin="12,26,136,12" />
</Grid>