2013-04-25 44 views
0

你好我希望我的列表框播放列表在最后一个文件播放后重复。 如何重置索引,以便重复到列表框的开始位置? Shownextimage逐一处理媒体以显示在媒体上。 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

也许这样的事情是你想要什么:

<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。我认为这应该在你的虚拟主机中处理。

+0

Hej Johan! Tackförsvar。 Hur kopplar jag滑块直到mitt mediaelement? 你好Johan,谢谢你的回答。如何将滑块与Mediaelement连接? – Sneakybastardd 2013-04-25 10:01:55

+0

也许我误解了你的问题,是在mediaelement“内部”的列表框? – 2013-04-25 10:04:42

+0

无论如何,您可以在我提供的代码中执行此操作吗? IF playlist ended reset Indexvalue to 1 或类似的东西 – Sneakybastardd 2013-04-25 10:15:04