0

您好,我希望我的列表框播放列表在播放最后一个文件后重复。如何重置索引以使其重复到列表框的开头?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);
    }
4

1 回答 1

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 中的 index 属性,该属性会在更改时发出通知。你的 index 属性应该在播放完一首歌曲后递增,如果这首歌是最后一首,则设置为 0。我认为这应该在你的虚拟机中处理。

于 2013-04-25T08:58:09.420 回答