Answer the question
In order to leave comments, you need to log in
How to load images asynchronously and display overall progress in the Progress Bar?
The essence of the task: write a WPF application that can load images from the Internet. You need to do this independently of other pictures. It should also be possible to load everything together. Overall progress is displayed on the Progress Bar.
Screenshot of the designed window:
I have a problem with events and passing parameters to them.
I imagine that there should be one function, for example, Downloading, which takes the address of an image on the Internet and draws this image in the corresponding box after downloading. Pressing one of the Start buttons calls this function with its URL and ImageBox. Saw something similar in this question: Progress Bar & Thread in C#?
private void Downloading(string url)
{
WebClient webload = new WebClient();
webload.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webload.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webload.DownloadFileAsync(new Uri(url), DataPath + Path.GetFileName(url));
}
ImageSourceConverter converter = new ImageSourceConverter();
ImageSource imageSource = (ImageSource)converter.ConvertFromString(DataPath + Path.GetFileName(url1));
ImageBox1.Source = imageSource;
Answer the question
In order to leave comments, you need to log in
We read what MVVM and async/await are, create a UserControl with type layout
<Grid>
<Image Source="{Binding Path=ViewModel.ImageSource, Mode=OneWay}"/>
<ProgressBar Value="{Binding Path=ViewModel.DownloadProgres, Mode=OneWay}"/>
</Grid>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question