I think I'm confusing some concepts and words here. It's easiest to describe in code.
What I have:
EditorVM
var webClient = new WebClient();
webClient.DownloadProgressChanged += (s, e) => pageVm.LoadingProgressValue = e.ProgressPercentage;
pageVm.WrapInDeterminedLoading(webClient.DownloadFileTaskAsync(new Uri(sourceUri), localPath), "Loading Video..");
PageVM
public async void WrapInDeterminedLoading(Task task, string text)
{
LoadingProgressValue = 0;
IsLoading = true;
IsLoadingProgressIndeterminate = false;
LoadingText = text;
await task;
IsLoading = false;
}
I'm wrapping all the logic I need to show something as loading within my PageVm. I want to do the DownloadProgressChanged
line within the PageVM. I tried simply putting a DownloadProgressChangedEventHandler
as a method argument, but I feel it's really not what I want.
How can I set it up in a way so that I'm forced to set up some kind of value to the LoadingProgressValue
?
I feel the third line does not belong in EditorVM. It's manually handling details of how loading works. I would like to have the PageVM class deal with that. But I need to react to the webclient's event somehow...
What I want and expected I could do somehow:
EditorVM:
var webClient = new WebClient();
pageVm.WrapInDeterminedLoading(webClient.DownloadFileTaskAsync(new Uri(sourceUri), localPath), "Loading Video..", webClient.DownloadProgressChanged);
PageVM
public async void WrapInDeterminedLoading(Task task, string text, ChangedHandler handler)
{
handler += (s, e) => LoadingProgressValue = e.ProgressPercentage;
LoadingProgressValue = 0;
IsLoading = true;
IsLoadingProgressIndeterminate = false;
LoadingText = text;
await task;
IsLoading = false;
}