我正在为进度条设置WPF项目。目前,它将根据静态值显示进度,进度将被称为“contentrendered”
<fo:basic-link internal-destination="${{variableOutside}}">
我正在考虑将这个项目整合到我的类库项目中。该类库将从服务器下载文件。我尝试了一些方法,但仍然没有成功。有人可以帮帮我吗?
private void Window_ContentRendered(object sender, EventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += worker_DoWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerAsync();
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < 100; i++)
{
(sender as BackgroundWorker).ReportProgress(i);
Thread.Sleep(100);
}
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
pbStatus.Value = e.ProgressPercentage;
}
答案 0 :(得分:0)
如果我说得对,你应该对此
WebClient myWebClient = new WebClient();
for (int i = 0; i < fileName.Count; i++)
{
myStringWebResource = uri + fileName[i];
myStringTempResource = appPath + "\\temp\\" + fileName[i];
myWebClient.DownloadFile(myStringWebResource, myStringTempResource);
(发件人为BackgroundWorker).ReportProgress(i); } 在
worker_DoWork(object sender, DoWorkEventArgs e)
只是报告我的价值,就像你在你的例子中所做的那样。
顺便说一句,ProgressBar有一个属性IsIndeterminate
,你也可以使用它。