public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var playlists = values[0] as IList <Playlist>; var viewModel = values[1] as ShellViewModel; if (playlists == null || viewModel == null) { return(null); } var result = new List <PlaylistItemViewModel>(playlists.Count); foreach (var playlist in playlists) { var menuItem = new PlaylistItemViewModel { Name = playlist.Name, Action = async() => { await viewModel.AddToPlaylist(playlist.Id); } }; result.Add(menuItem); } return(new ObservableCollection <PlaylistItemViewModel>(result)); }
/// <summary> /// 添加媒体文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdditem_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; ofd.Filter = "媒体文件|*.jpg;*.bmp;*.jpeg;*.png;*.wmv;"; ofd.ShowDialog(); if (!string.IsNullOrEmpty(ofd.FileName)) { PlaylistItemViewModel itemVM = new PlaylistItemViewModel(); itemVM.Name = ofd.SafeFileName; itemVM.FilePath = ofd.FileName; int sum = 0; if (itemVM.Name.Substring(itemVM.Name.LastIndexOf(".")) == ".wmv" || itemVM.Name.Substring(itemVM.Name.LastIndexOf(".")) == ".WMV") { Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder folder = shell.NameSpace(ofd.FileName.Substring(0, ofd.FileName.LastIndexOf("\\"))); Shell32.FolderItem folderitem = folder.ParseName(ofd.SafeFileName); string len; if (Environment.OSVersion.Version.Major >= 6) { len = folder.GetDetailsOf(folderitem, 27); } else { len = folder.GetDetailsOf(folderitem, 21); } string[] str = len.Split(new char[] { ':' }); sum = int.Parse(str[0]) * 3600 + int.Parse(str[1]) * 60 + int.Parse(str[2]) + 1; } else { if (Playlist.ItemList.Count > 0) { for (int i = Playlist.ItemList.Count - 1; i >= 0; i--) { if (Playlist.ItemList[i].Name.Substring(Playlist.ItemList[i].Name.LastIndexOf(".")) != ".WMV" && Playlist.ItemList[i].Name.Substring(Playlist.ItemList[i].Name.LastIndexOf(".")) != ".wmv") { sum = Playlist.ItemList[i].SunTime; break; } } } } if (sum == 0) { sum = 10; } itemVM.SunTime = sum; itemVM.Md5Value = SeatManage.SeatManageComm.SeatComm.GetMD5HashFromFile(itemVM.FilePath); Playlist.ItemList.Add(itemVM); } }
/// <summary> /// 下移 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btndown_Click(object sender, RoutedEventArgs e) { if (itemlistView.SelectedIndex > -1) { PlaylistItemViewModel selectitem = itemlistView.Items[itemlistView.SelectedIndex] as PlaylistItemViewModel; int index = Playlist.ItemList.IndexOf(selectitem); if (index < Playlist.ItemList.Count - 1) { Playlist.ItemList.Move(index, index + 1); } } }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btndelete_Click(object sender, RoutedEventArgs e) { if (itemlistView.SelectedIndex > -1) { MessageBoxResult endResult; endResult = MessageBox.Show("确认要删除此条媒体文件吗?", "删除提示", MessageBoxButton.YesNo, MessageBoxImage.Question); if (endResult == MessageBoxResult.Yes) { PlaylistItemViewModel selectitem = itemlistView.Items[itemlistView.SelectedIndex] as PlaylistItemViewModel; int index = Playlist.ItemList.IndexOf(selectitem); if (index < Playlist.ItemList.Count && index > -1) { Playlist.ItemList.RemoveAt(index); } } } }
/// <summary> /// 批量添加文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_AddloopMedia_Click(object sender, RoutedEventArgs e) { MediaEditWindow med = new MediaEditWindow(); med.Playlist = new PlaylistInfoViewModel(); med.ShowDialog(); if (med.Playlist.LoopList.Count > 0) { foreach (PlaylistItemViewModel loopitem in med.Playlist.LoopList) { PlaylistItemViewModel itemVM = new PlaylistItemViewModel(); itemVM.Name = loopitem.Name; itemVM.FilePath = loopitem.FilePath; itemVM.SunTime = loopitem.SunTime; itemVM.Md5Value = loopitem.Md5Value; Playlist.ItemList.Add(itemVM); } } }