I've been trying to bind the ProgressBar value inside a ListView item (custom control) to a subproperty (DownloadProgress) of each item inside the ObservableCollection property (VideoDisplayExternals) I have in my VM. My purpose for this is so that I can update the value of the ProgressBar while I'm downloading each video also inside each item.
Below is code for when I'm downloading. This is in a method in my VM.
foreach (VideoDisplayExternal videoDisplayExternal in VideoDisplayExternals)
{
Video video = videoDisplayExternal.Video;
var streamInfo = videoDisplayExternal.SelectedStream;
string fileName = $"{video.Title}.{streamInfo.Container}";
string downloadPath = System.IO.Path.Combine(playlistFolderPath, fileName);
// this works (progress value inside VideoDisplayExternal item is changed) but ProgressBar isn't updated
CurrentlyDownloadingVideoDisplayExternal = videoDisplayExternal;
var progressHandler = new Progress<double>(ShowDownloadProgress);
// download video
await youtube.Videos.Streams.DownloadAsync(streamInfo, downloadPath, progressHandler);
CurrentlyDownloadingVideoDisplayExternal = null;
}
These are my VM properties:
public ObservableCollection<VideoDisplayExternal> VideoDisplayExternals { get; set; }
private VideoDisplayExternal currentlyDownloadingVideoDisplayExternal;
public VideoDisplayExternal CurrentlyDownloadingVideoDisplayExternal
{
get { return currentlyDownloadingVideoDisplayExternal; }
set
{
currentlyDownloadingVideoDisplayExternal = value;
OnPropertyChanged("CurrentlyDownloadingVideoDisplayExternal");
}
}
These are my models:
public class VideoDisplayExternal
{
public bool IsCheckBoxChecked { get; set; }
public Video Video { get; set; }
public List<YoutubeExplode.Videos.Streams.MuxedStreamInfo> Streams { get; set; }
public YoutubeExplode.Videos.Streams.MuxedStreamInfo SelectedStream { get; set; }
public double DownloadProgress { get; set; }
}
public class Video
{
public int Id { get; set; }
public int VideoDownloadId { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string Url { get; set; }
public string ThumbnailUrl { get; set; }
public TimeSpan? Duration { get; set; }
}
And this is my ProgressBar binding (note that this is inside a UserControl thats' inside a ListView):
<ProgressBar Grid.Row="1"
Margin="10"
Maximum="100"
Minimum="0"
Value="{Binding DownloadProgress, Mode=OneWay,
UpdateSourceTrigger=PropertyChanged}"/>
I have never been so confused in my life so I hope some of you can guide me towards finding a solution for this. The ProgressBar doesn't seem to update at all although the DownloadProgress of each VideoDisplayExternal does change and even reaches 100 after downloading.