private void DownloadItem_StateChanged(object sender, DownloadSessionStateChangedEventArgs e) { var downloadItem = e.Session as DownloadItem; if (downloadItem == null) { return; } if (((e.OldState == DownloadState.Downloading) || (e.OldState == DownloadState.Paused) || (e.OldState == DownloadState.Ready)) && ((e.NewState == DownloadState.Cancelled) || (e.NewState == DownloadState.Failed) || (e.NewState == DownloadState.Success))) { Application.Current.Dispatcher.Invoke(() => { DownloadList.Remove(downloadItem); CompletedList.Add(downloadItem); }); } else if (CompletedList.Contains(downloadItem)) { Application.Current.Dispatcher.Invoke(() => { CompletedList.Remove(downloadItem); DownloadList.Add(downloadItem); }); } SetDownloadItemStatusText(downloadItem); }
private void RemoveDownloadItem(DownloadItem downloadItem) { if ((downloadItem == null) || !downloadItem.CanBeRemoved) { return; } DownloadList.Remove(downloadItem); CompletedList.Remove(downloadItem); }