UWP C#:IAsyncOperationWithProgress 的进度

UWP C# : Progress of IAsyncOperationWithProgress

如何捕获 IAsyncOperationWithProgress 的进度并将其发送到 ProgressBar

var packageManager = new PackageManager();
var packageUri = new Uri("https://example.com/");
var options = AddPackageByAppInstallerOptions.None;
var defaultPackageVolume = packageManager.GetDefaultPackageVolume();

var operation = packageManager.AddPackageByAppInstallerFileAsync(packageUri, options, defaultPackageVolume);

operation.Progress( ??? ); // What should I do?
MyProgressBar.Value = ???; // I'd like to display installation progress % in real time.

await operation;

调用最简单AsTask:

var progress = new Progress<DeploymentProgress>(
    report => myProgressBar.Value = report.Percentage);
var operation = packageManager.AddPackageByAppInstallerFileAsync(packageUri, options, defaultPackageVolume)
    .AsTask(progress);

await operation;

未编译和未测试;可能需要对 DeploymentProgress.Percentage 进行一些操作。