您好我希望我的列表框播放列表在播放完最后一个文件后重复播放。 如何重置索引以使其重复到列表框的开头? Shownextimage逐个处理媒体以在mediaelement上显示。 DispatcherTimer显示图像20秒,然后继续。
这就是我得到的。
Dictionary<string, string> Listbox1Dict = new Dictionary<string, string>();
public static List<string> images = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG" }; // Bildtyper som stöds
public static List<string> movies = new List<string> { ".WMV", ".WAV", ".SWF", ".MP4", ".MPG", ".AVI" };
List<string> paths = new List<string>();
DispatcherTimer dispatcherTimer = new DispatcherTimer();
DispatcherTimer NextImageTimer = new DispatcherTimer();
int x = 20;
private int currentSongIndex = -1;
private void ShowNextImage()
{
if (currentSongIndex == -1)
{
currentSongIndex = Listbox1.SelectedIndex;
}
currentSongIndex++;
var selected = Listbox1.Items[currentSongIndex];
string s = selected.ToString();
if (Listbox1Dict.ContainsKey(s))
{
if (images.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant()))
{
if (currentSongIndex < Listbox1.Items.Count)
{
mediaElement1.Source = new Uri(Listbox1Dict[s]);
}
}
else if (movies.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant()))
{
if (currentSongIndex < Listbox1.Items.Count)
{
dispatcherTimer.Stop();
mediaElement1.Source = new Uri(Listbox1Dict[s]);
}
}
}
}
计时器:
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
ShowNextImage();
}
private void dispatch()
{
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, x);
}
答案 0 :(得分:0)
也许这样的事情就是你想要的:
<StackPanel>
<ListBox SelectedIndex="{Binding ElementName=Index, Path=Value}">
<ListBoxItem>First</ListBoxItem>
<ListBoxItem>Second</ListBoxItem>
<ListBoxItem>Third</ListBoxItem>
</ListBox>
<Slider x:Name="Index" Minimum="0" Maximum="2" Value="2" TickFrequency="1" IsSnapToTickEnabled="True" TickPlacement="BottomRight"/>
</StackPanel>
在此示例中,列表框的选定索引绑定到滑块的值。滑块应该由ViewModel中的indexproperty替换,该属性会在更改时通知。完成播放歌曲后,索引道具应增加,如果歌曲是最后一首,则设置为0。我认为这应该在你的vm中处理。