c# - Repeat a listbox that opens files -
hello want listbox playlist repeat after last file played. how reset index repeats start of listbox? shownextimage handles media 1 one show on mediaelement. dispatchertimer shows images 20 seconds , continues.
this got.
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]); } } } }
the timers:
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); }
maybe want:
<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>
in sample selected index of listbox bound value of slider. slider should replaced indexproperty in viewmodel notifies when changed. index prop should increment after finishing playing song , set 0 if song last. think should handled in vm.