我的 MainPage.xaml 中有一个 ProgressBar:
<ProgressBar HorizontalAlignment="Center"
Height="90" Margin="0,-30,0,0"
VerticalAlignment="Center"
Width="600" x:Name="BarProgress" />
然后在 MainPage.xaml.cs 中有下载数据的代码:
public async Task Download(string fileName, string fileId)
private async Task HandleDownloadAsync(DownloadOperation download, bool start)
private async Task DiscoverActiveDownloadsAsync()
private void DownloadProgress(DownloadOperation download)
{
double percent = 100;
if (download.Progress.TotalBytesToReceive > 0)
{
percent = download.Progress.BytesReceived * 100 / download.Progress.TotalBytesToReceive;
}
BarProgress.Value = percent;
}
而且效果很好!我可以看到 ProgressBar 继续进行,直到下载结束!
但是,如果我想创建一个新类,例如 DownloadData.xaml.cs,然后将所有用于下载数据的代码放入其中,我该如何调用 BarProgress.Value?!?我做了很多尝试,比如 MainPage.BarProgress.Value = percent,但我收到很多错误,因为 BarProgress 无法访问...