public DownloadedTaskViewModel(DownloadingTaskViewModel task) { fullPath = task.CurrentFileFullPath; Name = task.Name; CompletedTime = DateTime.Now; OpenCommand = new DependencyCommand(Open, DependencyCommand.AlwaysCan); ShowCommand = new DependencyCommand(Show, DependencyCommand.AlwaysCan); DeleteCommand = new DependencyCommand(Delete, DependencyCommand.AlwaysCan); }
private static void Add(bool isAutoStart, DownloadingTaskViewModel task) { App.Current.Dispatcher.Invoke(() => { _observableCollection.Add(task); }); if (isAutoStart) { task.Start(); } }
public static void NewCompleted(DownloadingTaskViewModel task) { DownloadedTaskViewModel record = new DownloadedTaskViewModel(task); App.Current.Dispatcher.Invoke(() => _observableCollection.Insert(0, record)); record.Deleted += RemoveAfterDeleted; void RemoveAfterDeleted(object sender, EventArgs e) { record.Deleted -= RemoveAfterDeleted; App.Current.Dispatcher.Invoke(() => _observableCollection.Remove(record)); } }
public static void NewTask(string downloadAddress, string localPath, string name, bool isAutoStart = true) { DownloadingTaskViewModel task = new DownloadingTaskViewModel(downloadAddress, localPath, name); //当下载任务结束时从列表中移除任务信息 task.DownloadCompleted += (sender, e) => { App.Current.Dispatcher.Invoke(() => { try { _observableCollection.Remove(task); if (File.Exists(task.CurrentFileFullPath)) { DownloadedListViewModel.NewCompleted(task); } } catch (Exception) { } }); }; Add(isAutoStart, task); }