using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Net; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; namespace WpfApp2 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } public class ViewModel { CollectionViewSource cvs = new CollectionViewSource(); public ICollectionView View { get => cvs.View; } public ObservableCollection MyClients; public ViewModel() { cvs.Source = GetData(); } private ObservableCollection GetData() { ObservableCollection MyClients = new ObservableCollection(); MyClients.Add(new Clients() { Id = 1, Text = "https://sample-videos.com/doc/Sample-doc-file-1000kb.doc" }); MyClients.Add(new Clients() { Id = 3, Text = "https://freetestdata.com/wp-content/uploads/2021/09/1-MB-DOC.doc" }); MyClients.Add(new Clients() { Id = 2, Text = "https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_500KB_DOC.doc" }); return MyClients; } } public class Clients : ICommand, INotifyPropertyChanged { public Clients() => disp = Dispatcher.CurrentDispatcher; private Dispatcher disp; public int Id { get; set; } public string Text { get; set; } WebClient client1 = new WebClient(); public void Execute(object parameter) { if (client1.IsBusy) return; Progress = 0; Uri uri = new Uri(Text); String FileName = System.IO.Path.GetFileName(uri.AbsolutePath); client1.DownloadFileAsync(uri, @"C:\Users\Administrator\Desktop\" + FileName); client1.DownloadProgressChanged += downloadprogress; } public double Progress { get; set; } private void downloadprogress(object sender, DownloadProgressChangedEventArgs e) { Progress = e.ProgressPercentage; OnPropertyChanged(nameof(Progress)); } public event EventHandler CanExecuteChanged; public bool CanExecute(object parameter) => true; public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged([CallerMemberName] string propName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); } }